yifan commited on
Commit
d0dd2e4
1 Parent(s): 217053a

add more details example

Browse files
Files changed (1) hide show
  1. README.md +11 -0
README.md CHANGED
@@ -28,9 +28,20 @@ https://propaganda.qcri.org/annotations/definitions.html
28
  ## How to use
29
 
30
  ```python
 
31
  >>> from .model import BertForTokenAndSequenceJointClassification
 
 
32
  >>> model = BertForTokenAndSequenceJointClassification.from_pretrained(
33
  >>> "QCRI/PropagandaTechniquesAnalysis-en-BERT",
34
  >>> revision="v0.1.0",
35
  >>> )
 
 
 
 
 
 
 
 
36
  ```
 
28
  ## How to use
29
 
30
  ```python
31
+ >>> from transformers import BertTokenizerFast
32
  >>> from .model import BertForTokenAndSequenceJointClassification
33
+ >>>
34
+ >>> tokenizer = BertTokenizerFast.from_pretrained('bert-base-cased')
35
  >>> model = BertForTokenAndSequenceJointClassification.from_pretrained(
36
  >>> "QCRI/PropagandaTechniquesAnalysis-en-BERT",
37
  >>> revision="v0.1.0",
38
  >>> )
39
+ >>>
40
+ >>> inputs = tokenizer.encode_plus("Hello, my dog is cute", return_tensors="pt")
41
+ >>> outputs = model(**inputs)
42
+ >>> sequence_class_index = torch.argmax(outputs.sequence_logits, dim=-1)
43
+ >>> sequence_class = model.sequence_tags[sequence_class_index[0]]
44
+ >>> token_class_index = torch.argmax(outputs.token_logits, dim=-1)
45
+ >>> tokens = tokenizer.convert_ids_to_tokens(inputs.input_ids[0][1:-1])
46
+ >>> tags = [model.token_tags[i] for i in token_class_index[0].tolist()[1:-1]]
47
  ```