Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3def sentence_cls_score(input_strings, predicate_cls_model, predicate_cls_tokenizer):
4 tokenized_cls_input = predicate_cls_tokenizer(input_strings, truncation=True, padding=True,
5 return_token_type_ids=True)
6 input_ids = torch.Tensor(tokenized_cls_input['input_ids']).long().to(torch.device("cuda"))
7 token_type_ids = torch.Tensor(tokenized_cls_input['token_type_ids']).long().to(torch.device("cuda"))
8 attention_mask = torch.Tensor(tokenized_cls_input['attention_mask']).long().to(torch.device("cuda"))
9 prev_cls_output = predicate_cls_model(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
10 softmax_cls_output = torch.softmax(prev_cls_output.logits, dim=1, )
11 return softmax_cls_output
12
13
14tokenizer = AutoTokenizer.from_pretrained("Inria-CEDAR/FactSpotter-DeBERTaV3-Large")
15model = AutoModelForSequenceClassification.from_pretrained("Inria-CEDAR/FactSpotter-DeBERTaV3-Large")
16model.to(torch.device("cuda"))
17
18# pairs of texts (as premises) and triples (as hypotheses)
19cls_texts = [("the aarhus is the airport of aarhus, denmark", "aarhus airport, city served, aarhus, denmark"),
20 ("aarhus airport is 25.0 metres above the sea level", "aarhus airport, elevation above the sea level, 1174")]
21cls_scores = sentence_cls_score(cls_texts, model, tokenizer)
22# Dimensions: 0-entailment, 1-neutral, 2-contradiction
23label_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},
}