zaemyung commited on
Commit
76f1cec
1 Parent(s): b9e1533

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -0
README.md CHANGED
@@ -1,3 +1,55 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ datasets:
4
+ - zaemyung/IteraTeR_plus
5
+ language:
6
+ - en
7
  ---
8
+ # DElIteraTeR-RoBERTa-Intent-Span-Detector
9
+ This model was obtained by fine-tuning [roberta-large](https://huggingface.co/roberta-large) on [IteraTeR+](https://huggingface.co/datasets/zaemyung/IteraTeR_plus) `multi_sent` dataset.
10
+
11
+ Paper: [Improving Iterative Text Revision by Learning Where to Edit from Other Revision Tasks](https://aclanthology.org/2022.emnlp-main.678/) <br>
12
+ Authors: Zae Myung Kim, Wanyu Du, Vipul Raheja, Dhruv Kumar, and Dongyeop Kang
13
+
14
+ ## Usage
15
+ ```python
16
+ import torch
17
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
18
+
19
+ tokenizer = AutoTokenizer.from_pretrained("zaemyung/DElIteraTeR-RoBERTa-Intent-Span-Detector")
20
+
21
+ # update tokenizer with special tokens
22
+ INTENT_CLASSES = ['none', 'clarity', 'fluency', 'coherence', 'style', 'meaning-changed'] # `meaning-changed` is not used
23
+ INTENT_OPENED_TAGS = [f'<{intent_class}>' for intent_class in INTENT_CLASSES]
24
+ INTENT_CLOSED_TAGS = [f'</{intent_class}>' for intent_class in INTENT_CLASSES]
25
+ INTENT_TAGS = set(INTENT_OPENED_TAGS + INTENT_CLOSED_TAGS)
26
+ special_tokens_dict = {'additional_special_tokens': ['<bos>', '<eos>'] + list(INTENT_TAGS)}
27
+ tokenizer.add_special_tokens(special_tokens_dict)
28
+
29
+ model = AutoModelForTokenClassification.from_pretrained("zaemyung/DElIteraTeR-RoBERTa-Intent-Span-Detector")
30
+
31
+ id2label = {0: "none", 1: "clarity", 2: "fluency", 3: "coherence", 4: "style", 5: "meaning-changed"}
32
+
33
+ before_text = '<bos>I likes coffee?<eos>'
34
+ model_input = tokenizer(before_text, return_tensors='pt')
35
+ model_output = model(**model_input)
36
+ softmax_scores = torch.softmax(model_output.logits, dim=-1)
37
+ pred_ids = torch.argmax(softmax_scores, axis=-1)[0].tolist()
38
+ pred_intents = [id2label[_id] for _id in pred_ids]
39
+
40
+ tokens = tokenizer.convert_ids_to_tokens(model_input['input_ids'][0])
41
+
42
+ for token, pred_intent in zip(tokens, pred_intents):
43
+ print(f"{token}: {pred_intent}")
44
+
45
+ """
46
+ <s>: none
47
+ <bos>: none
48
+ I: fluency
49
+ Ġlikes: fluency
50
+ Ġcoffee: none
51
+ ?: none
52
+ <eos>: none
53
+ </s>: none
54
+ """
55
+ ```