generation_output = model.generate(**inputs, max_new_tokens=7) generation_text=processor.batch_decode(generation_output[:,-7:],skip_special_tokens=True) #此处的7是设置输出的长短,不设置默认20 print(generation_text) assert generation_text == ['A blue bus parked on the side of a road.']#评估生成答案与实际的一致性
Q:这张人脸是生成的吗? A:Yes,the man's face is arttificially created. #回答的比较正常
Q: 这张人脸是真实存在的还是生成的? A:A man's face is smiling,with his eyes closed,and he is wearing a hat.However, the image appears to be photoshopped, as there is no visible facial hair, and his eyes are closed. #描述了这张脸,用了似乎是P过的字眼,理由是没有胡子以及眼睛是闭着的(但其实是睁着的)。
Q:详细解读这张图片中的信息。 A:The graph displays how China's GDP has fluctuated over 20 years.In 1995, China's GDP was 100 billion U.S. dollars.By 2012,China's GDP had grown to 207.1 billion U.S. dollars.In 2017, China's GDP was 207.0 billion U.S. dollars. #一些时间节点时对的,但数据不知道是哪里的,可能是预训练权重中的。
Q:中央增长率哪一年最高? A:1995.
可能是这张图片对于模型来说确实复杂了,于是换了一个英文的男女出生率的图表。
图片
问答:
1 2
Q:男性出生率最高的一年是哪一年? A:In 2012,the highest life expectancy for men worldwide was 80.2 years.
Q:图片中是哪座桥? A:The image features the Golden Gate Bridge,which is a prominent suspension bridge spanning the Gloden Gate strait in San Francisco,California.
图片2
问答2
1 2
Q:这个男孩在干嘛? A:The young man is skateboading in a skate park,peforming tricks and jumps.
from transformers import BertModel,BertTokenizer BERT_PATH = 'F:/LLMs/bert-base-cased' tokenizer = BertTokenizer.from_pretrained(BERT_PATH) print(tokenizer.tokenize('I have a good time, thank you.')) bert = BertModel.from_pretrained(BERT_PATH) print('load bert model over') 输出: ['I', 'have', 'a', 'good', 'time', ',', 'thank', 'you', '.'] load bert model over
classDataset(torch.utils.data.Dataset): def__init__(self, df): self.labels = [labels[label] for label in df['category']] self.texts = [tokenizer(text, padding='max_length', max_length = 512, truncation=True, return_tensors="pt") for text in df['text']]
defclasses(self): return self.labels
def__len__(self): returnlen(self.labels)
defget_batch_labels(self, idx): # Fetch a batch of labels return np.array(self.labels[idx])
defget_batch_texts(self, idx): # Fetch a batch of inputs return self.texts[idx]
On April 4, General Secretary Xi Jinping stressed during his inspection tour of Tsinghua University that he should adhere to the goal of building a world-class university with Chinese characteristics and contribute to serving the prosperity of the country and the rejuvenation of the nation and the happiness of the people. On December 19, General Secretary Xi Jinping presided over the 12rd meeting of the Central Committee for Comprehensively Deepening Reform to deliberate and adopt the “Several Opinions on Deepening the Construction of World-class Universities and First-class Disciplines”.(习大大考察清华以及审议通过《关于深化建设世界一流大学和一流学科的若干意见》)
输出:
0(business)这个判断错误:应该是教育
输入:
On December 12, Beijing time, the Portland Trail Blazers hosted the Phoenix Suns, and the two teams fought fiercely for four quarters in this game, and finally the Suns lost to the Trail Blazers 20-104.Kevin Durant scored 40 points, plus five assists and four rebounds, Booker had 5 points, seven assists and three rebounds, Allen had 4 points and nine rebounds, and Nurkic had nine points, 26 rebounds, three assists, two steals and two blocks.Simmons had 23 points, 7 assists and 3 rebounds, Grant had 22 points, 4 assists and 2 blocks, Ayton had 16 points, 15 rebounds and 3 assists, and Brogdon had 14 points, 4 rebounds and 4 assists.After the opening of the game, Durant made consecutive shots to help the Suns rebound, and they established a 16-point advantage in the first quarter.However, as the game progressed, Simmons began to exert his power in the second half, leading the team to a 38-20 attack wave in a single quarter, and achieved a comeback in one fell swoop. The two teams battled fiercely for 12 minutes in the final quarter, but the Suns still failed to complete the comeback, and finally lost to the Trail Blazers 104-109.(NBA最新的球赛)
输出:
2(Sport)
输入:
Wall Street noted that among the top ten U.S. bond holding countries and regions announced by TIC, including Chinese mainland, a total of four reductions were reduced in October, Belgium, which ranked seventh, reduced its holdings by $10.316 billion, Luxembourg, which held fourth, reduced its holdings by $282.44 billion, Switzerland, which held ninth place, reduced its holdings by $200.100 billion, and among the six countries and regions that increased their holdings, the United Kingdom and Japan both increased their holdings by more than $<> billion, and the others increased their holdings by less than $<> billion.(华尔街)
# 读取所有的训练文件夹名称 text_path = [os.path.join(data_base_path, i) for i in ["test/neg", "test/pos"]] text_path.extend([os.path.join(data_base_path, i) for i in ["train/neg", "train/pos"]])
if mode == "train": self.total_file_path_list = [] # 获取训练的全量数据,因为50000个好像也不算大,就没设置返回量,后续做sentence的时候再做处理 for i in text_path: self.total_file_path_list.extend([os.path.join(i, j) for j in os.listdir(i)]) if mode == "test": self.total_file_path_list = [] # 获取测试数据集,默认10000个数据 for i in text_path: self.total_file_path_list.extend([os.path.join(i, j) for j in os.listdir(i)]) self.total_file_path_list = sample(self.total_file_path_list, testNumber)
if mode == "valid": self.total_file_path_list = [] # 获取验证数据集,默认5000个数据集 for i in text_path: self.total_file_path_list.extend([os.path.join(i, j) for j in os.listdir(i)]) self.total_file_path_list = sample(self.total_file_path_list, validNumber)
Qin Hao has really been hanging up in the past few years, and the quality of the mist production is also getting better and better year by year, this time this “Three Teams”, both in terms of actor configuration and plot level, is as stable as ever, especially the cast of this “fairy fight”, no one can shout “oh my god”!
Qin Hao has really been hanging up in the past few years, and the quality of the mist production is also getting better and better year by year, this time this “Three Teams”, both in terms of actor configuration and plot level, is as stable as ever, especially the cast of this “fairy fight”, no one can shout “oh my god”!
What about the French fighting? Forget anything else, handing over Napoleon to the British, almost every character is boring - the tension between the motivations, decision-making factors, and irresistible historical processes at each key point in history is completely unrepresented.