Views
No views yet

1import torch,gc
2
3import transformers
4from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, BitsAndBytesConfig
5from datasets import load_dataset
6from peft import LoraConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training
7
8from transformers import (
9 AutoModelForCausalLM,
10 AutoTokenizer,
11 BitsAndBytesConfig,
12 HfArgumentParser,
13 TrainingArguments,
14 pipeline,
15 logging,
16 GenerationConfig,
17 TextIteratorStreamer,
18)
19
20from transformers import StoppingCriteria, StoppingCriteriaList
21
22import os
23
24
25model_id="NickyNicky/Financial_graph"
26
27max_seq_length=4048
28
29tokenizer = AutoTokenizer.from_pretrained(model_id,
30 token=access_token,
31 max_length=max_seq_length)
32model = AutoModelForCausalLM.from_pretrained(model_id,
33 # quantization_config=bnb_config,
34 device_map={"":0},
35 token=access_token,
36 attn_implementation="flash_attention_2",
37 torch_dtype=torch.bfloat16
38 ).eval()
39
40
41
42# dpo_trainer.model.config.use_cache = True # silence the warnings. Please re-enable for inference!
43# tokenizer.padding_side='left'
44
45class ListOfTokensStoppingCriteria(StoppingCriteria):
46 """
47 Clase para definir un criterio de parada basado en una lista de tokens específicos.
48 """
49 def __init__(self, tokenizer, stop_tokens):
50 self.tokenizer = tokenizer
51 # Codifica cada token de parada y guarda sus IDs en una lista
52 self.stop_token_ids_list = [tokenizer.encode(stop_token, add_special_tokens=False) for stop_token in stop_tokens]
53
54 def __call__(self, input_ids, scores, **kwargs):
55 # Verifica si los últimos tokens generados coinciden con alguno de los conjuntos de tokens de parada
56 for stop_token_ids in self.stop_token_ids_list:
57 len_stop_tokens = len(stop_token_ids)
58 if len(input_ids[0]) >= len_stop_tokens:
59 if input_ids[0, -len_stop_tokens:].tolist() == stop_token_ids:
60 return True
61 return False
62
63# Uso del criterio de parada personalizado
64stop_tokens = ["<end_of_turn>"] # Lista de tokens de parada
65
66# Inicializa tu criterio de parada con el tokenizer y la lista de tokens de parada
67stopping_criteria = ListOfTokensStoppingCriteria(tokenizer, stop_tokens)
68
69# Añade tu criterio de parada a una StoppingCriteriaList
70stopping_criteria_list = StoppingCriteriaList([stopping_criteria])
71
72
73
74prompt= """<bos><start_of_turn>system
75Eres un agente experto en finanzas multilenguaje.<end_of_turn>
76<start_of_turn>user
77**news:**
78In a sudden decision, investment firm 21Shares submitted a filing to the Securities and Exchange Commission in the late afternoon of Friday, May 31, to rename its proposed spot Ether
79ETH
80tickers down
81$3,686
82exchange-traded fund (ETF) and to remove ARK Invest from the application.
83A spokesperson for ARK Invest later confirmed the firm decided not to move forward with the crypto product, citing a need to reassess its investment strategy. The move raised concerns among the crypto community concerning the short-term viability of the newly approved ETFs.
84During an interview on June 5, United States Securities and Exchange Commission (SEC) Chair Gary Gensler suggested a delay in final approvals for asset managers. ETFs will “take some time,” said Gensler. The SEC has yet to sign off on S-1 registration statements from applicants.
85ARK Invest and 21Shares will remain partners on their spot Bitcoin
86BTC
87tickers down
88$69,346
89ETF, launched in January.
90This week’s Crypto Biz also explores Galaxy Digital’s tokenized loan for Animoca Brands, Avail’s fundraising, the Toposware acquisition, and Bitcoin miners’ first reports since the halving.
91Galaxy Digital uses historic violin NFT to secure loan
92Michael Novogratz’s Galaxy Digital and Animoca Brands co-founder Yat Siu have tokenized a Stradivarius violin from 1708 to use as collateral for a multimillion-dollar loan. On June 4, Galaxy reportedly lent an undisclosed amount of funds to Siu, who used the 316-year-old violin he owned as collateral. The digital assets firm turned the violin into a nonfungible token (NFT) and will hold the NFT and the physical version until Siu settles the loan. The violin once belonged to the Russian Empress Catherine the Great.
93
94genera un grafo de razonamiento que contenga nodes: 10 y edges: 20<end_of_turn>
95<start_of_turn>model
96"""
97
98input= tokenizer(prompt,
99 return_tensors="pt",
100 add_special_tokens=False).to(model.device)
101
102max_new_tokens=1500
103generation_config = GenerationConfig(
104 max_new_tokens = max_new_tokens,
105 temperature = .3,
106 # top_p=0.55,
107 # top_k = 50,
108 # repetition_penalty = 1.1,
109 do_sample=True,
110 )
111outputs = model.generate(**input,
112 generation_config=generation_config,
113 stopping_criteria=stopping_criteria_list,
114 )
115print(tokenizer.decode(outputs[0], skip_special_tokens=False) )
116
117##output:
118# {'nodes': [{'entity': 'ARK Invest', 'type': 'Organization'}, {'entity': '21Shares', 'type': 'Organization'}, {'entity': 'SEC', 'type': 'Organization'}, {'entity': 'Gary Gensler', 'type': 'Person'}, {'entity': 'United States Securities and Exchange Commission', 'type': 'Organization'}, {'entity': 'Galaxy Digital', 'type': 'Organization'}, {'entity': 'Animoca Brands', 'type': 'Organization'}, {'entity': 'Toposware', 'type': 'Organization'}, {'entity': 'Bitcoin miners', 'type': 'Organization'}, {'entity': 'S-1 registration statements', 'type': 'Document'}], 'edges': [{'from': 'ARK Invest', 'to': '21Shares', 'relation': 'ASSOCIATED_WITH'}, {'from': 'ARK Invest', 'to': 'SEC', 'relation': 'ASSOCIATED_WITH'}, {'from': 'ARK Invest', 'to': 'Gary Gensler', 'relation': 'ASSOCIATED_WITH'}, {'from': '21Shares', 'to': 'SEC', 'relation': 'ASSOCIATED_WITH'}, {'from': '21Shares', 'to': 'Gary Gensler', 'relation': 'ASSOCIATED_WITH'}, {'from': 'SEC', 'to': 'Gary Gensler', 'relation': 'WORKED_AT'}, {'from': 'SEC', 'to': 'United States Securities and Exchange Commission', 'relation': 'PART_OF'}, {'from': 'Galaxy Digital', 'to': 'Animoca Brands', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Galaxy Digital', 'to': 'Toposware', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Galaxy Digital', 'to': 'Bitcoin miners', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Galaxy Digital', 'to': 'S-1 registration statements', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Animoca Brands', 'to': 'Toposware', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Toposware', 'to': 'Bitcoin miners', 'relation': 'ASSOCIATED_WITH'}, {'from': 'Bitcoin miners', 'to': 'S-1 registration statements', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': 'SEC', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': 'Galaxy Digital', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': 'Animoca Brands', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': 'Toposware', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': 'Bitcoin miners', 'relation': 'ASSOCIATED_WITH'}, {'from': 'S-1 registration statements', 'to': '21Shares', 'relation': 'ASSOCIATED_WITH'}]}


better than BloombergGPT :Vhttps://colab.research.google.com/drive/1-D7kgig6ODqhjCPaQBrZ8QG2OWsS29ML?usp=sharing