Views
No views yet
1from transformers import BertForSequenceClassification, BertTokenizer
2model_path = 'THEATLAS/FactCC-PENS'
3
4tokenizer = BertTokenizer.from_pretrained(model_path)
5model = BertForSequenceClassification.from_pretrained(model_path)
6
7text='''The US has "passed the peak" on new coronavirus cases, the White House reported. They predict that some states would reopen this month.
8The US has over 637,000 confirmed Covid-19 cases and over 30,826 deaths, the highest for any country in the world.'''
9wrong_summary = '''The pandemic has almost not affected the US'''
10
11input_dict = tokenizer(text, wrong_summary, max_length=512, padding='max_length', truncation='only_first', return_tensors='pt')
12logits = model(**input_dict).logits
13
14probs = torch.nn.functional.softmax(logits, dim=1)
15fact_scores = probs[0][0].item()
16
17print(f"fact_scores: {fact_scores}")1from transformers import BertForSequenceClassification, BertTokenizer
2model_path = 'THEATLAS/FactCC-PENS'
3
4tokenizer = BertTokenizer.from_pretrained(model_path)
5model = BertForSequenceClassification.from_pretrained(model_path)
6
7text='''The US has "passed the peak" on new coronavirus cases, the White House reported. They predict that some states would reopen this month.
8The US has over 637,000 confirmed Covid-19 cases and over 30,826 deaths, the highest for any country in the world.'''
9wrong_summary = '''The pandemic has almost not affected the US'''
10
11input_dict = tokenizer(text, wrong_summary, max_length=512, padding='max_length', truncation='only_first', return_tensors='pt')
12logits = model(**input_dict).logits
13pred = logits.argmax(dim=1)
14model.config.id2label[pred.item()] # prints: INCORRECT1>>> from transformers import pipeline
2
3>>> pipe=pipeline(model="THEATLAS/FactCC-PENS")
4>>> pipe([[[text1,summary1]],[[text2,summary2]]],truncation='only_first',padding='max_length')
5# output [{'label': 'INCORRECT', 'score': 0.9979124665260315}, {'label': 'CORRECT', 'score': 0.879124665260315}]