Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3
4def sentence_cls_score(input_strings, predicate_cls_model, predicate_cls_tokenizer):
5 tokenized_cls_input = predicate_cls_tokenizer(input_strings, truncation=True, padding=True,
6 return_token_type_ids=True)
7 input_ids = torch.Tensor(tokenized_cls_input['input_ids']).long().to(torch.device("cuda"))
8 token_type_ids = torch.Tensor(tokenized_cls_input['token_type_ids']).long().to(torch.device("cuda"))
9 attention_mask = torch.Tensor(tokenized_cls_input['attention_mask']).long().to(torch.device("cuda"))
10 prev_cls_output = predicate_cls_model(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
11 softmax_cls_output = torch.softmax(prev_cls_output.logits, dim=1, )
12 return softmax_cls_output
13
14
15tokenizer = AutoTokenizer.from_pretrained("Inria-CEDAR/FactSpotter-DeBERTaV3-Small")
16model = AutoModelForSequenceClassification.from_pretrained("Inria-CEDAR/FactSpotter-DeBERTaV3-Small")
17model.to(torch.device("cuda"))
18
19# pairs of texts (as premises) and triples (as hypotheses)
20cls_texts = [("the aarhus is the airport of aarhus, denmark", "aarhus airport, city served, aarhus, denmark"),
21 ("aarhus airport is 25.0 metres above the sea level", "aarhus airport, elevation above the sea level, 1174")]
22cls_scores = sentence_cls_score(cls_texts, model, tokenizer)
23# Dimensions: 0-entailment, 1-neutral, 2-contradiction
24label_names = ["entailment", "neutral", "contradiction"]@inproceedings{zhang:hal-04257838,
TITLE = {{FactSpotter: Evaluating the Factual Faithfulness of Graph-to-Text Generation}},
AUTHOR = {Zhang, Kun and Balalau, Oana and Manolescu, Ioana},
URL = {https://hal.science/hal-04257838},
BOOKTITLE = {{Findings of EMNLP 2023 - Conference on Empirical Methods in Natural Language Processing}},
ADDRESS = {Singapore, Singapore},
YEAR = {2023},
MONTH = Dec,
KEYWORDS = {Graph-to-Text Generation ; Factual Faithfulness ; Constrained Text Generation},
PDF = {https://hal.science/hal-04257838/file/_EMNLP_2023__Evaluating_the_Factual_Faithfulness_of_Graph_to_Text_Generation_Camera.pdf},
HAL_ID = {hal-04257838},
HAL_VERSION = {v1},
}