balhafni commited on
Commit
51a8dcd
·
verified ·
1 Parent(s): 3d5d32c

Update README.md

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