balhafni commited on
Commit
a162d77
·
verified ·
1 Parent(s): 5d96614

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -17,6 +17,51 @@ This model was introduced in our ACL 2025 paper, [Enhancing Text Editing for Gra
17
  The model was fine-tuned to fix punctuation (i.e., Pnx) errors. Details about the training procedure, data preprocessing, and hyperparameters are available in the paper.
18
  The fine-tuning code and associated resources are publicly available on our GitHub repository: https://github.com/CAMeL-Lab/text-editing.
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
 
22
  ## Citation
 
17
  The model was fine-tuned to fix punctuation (i.e., Pnx) errors. Details about the training procedure, data preprocessing, and hyperparameters are available in the paper.
18
  The fine-tuning code and associated resources are publicly available on our GitHub repository: https://github.com/CAMeL-Lab/text-editing.
19
 
20
+ ## Intended uses
21
+ To use the `CAMeL-Lab/text-editing-qalb14-pnx` model, you must clone our text editing [GitHub repository](https://github.com/CAMeL-Lab/text-editing) and follow the installation requirements.
22
+ We used this SWEET<sub>Pnx</sub> model to report results on the QALB-2014 dev and test sets in our [paper](https://arxiv.org/abs/2503.00985).
23
+ This model is intended to be used with SWEET<sub>NoPnx</sub> ([`CAMeL-Lab/text-editing-qalb14-nopnx`](https://huggingface.co/CAMeL-Lab/text-editing-qalb14-nopnx)) model.
24
+
25
+ ## How to use
26
+ Clone our text editing [GitHub repository](https://github.com/CAMeL-Lab/text-editing) and follow the installation requirements
27
+
28
+ ```python
29
+ from transformers import BertTokenizer, BertForTokenClassification
30
+ import torch
31
+ import torch.nn.functional as F
32
+ from gec.tag import rewrite
33
+
34
+
35
+ nopnx_tokenizer = BertTokenizer.from_pretrained('CAMeL-Lab/text-editing-qalb14-nopnx')
36
+ nopnx_model = BertForTokenClassification.from_pretrained('CAMeL-Lab/text-editing-qalb14-nopnx')
37
+
38
+ pnx_tokenizer = BertTokenizer.from_pretrained('CAMeL-Lab/text-editing-qalb14-pnx')
39
+ pnx_model = BertForTokenClassification.from_pretrained('CAMeL-Lab/text-editing-qalb14-pnx')
40
+
41
+
42
+ def predict(model, tokenizer, text, decode_iter=1):
43
+ for _ in range(decode_iter):
44
+ tokenized_text = tokenizer(text, return_tensors="pt", is_split_into_words=True)
45
+ with torch.no_grad():
46
+ logits = model(**tokenized_text).logits
47
+ preds = F.softmax(logits.squeeze(), dim=-1)
48
+ preds = torch.argmax(preds, dim=-1).cpu().numpy()
49
+ edits = [model.config.id2label[p] for p in preds[1:-1]]
50
+
51
+ assert len(edits) == len(tokenized_text['input_ids'][0][1:-1])
52
+ subwords = tokenizer.convert_ids_to_tokens(tokenized_text['input_ids'][0][1:-1])
53
+ text = rewrite(subwords=[subwords], edits=[edits])[0][0]
54
+ return text
55
+
56
+
57
+ text = 'يجب الإهتمام ب الصحه و لا سيما ف ي الصحه النفسيه ياشباب المستقبل،،'.split()
58
+
59
+ output_sent = predict(nopnx_model, nopnx_tokenizer, text, decode_iter=2)
60
+ output_sent = predict(pnx_model, pnx_tokenizer, output_sent.split(), decode_iter=1)
61
+ print(output_sent) # يجب الاهتمام بالصحة ولا سيما في الصحة النفسية يا شباب المستقبل .
62
+
63
+ ```
64
+
65
 
66
 
67
  ## Citation