danyaljj commited on
Commit
a9858c4
1 Parent(s): 8d79ec8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -18
README.md CHANGED
@@ -5,7 +5,7 @@ language:
5
  thumbnail: "https://upload.wikimedia.org/wikipedia/commons/a/a2/Farsi.svg"
6
  tags:
7
  - entailment
8
- - parsbert
9
  - persian
10
  - farsi
11
  license: "CC BY-NC-SA 4.0"
@@ -22,36 +22,33 @@ This is a model for textual entailment problems.
22
  Here is an example of how you can run this model:
23
 
24
  ```python
25
- import torch
26
- from transformers import AutoModelForSequenceClassification, AutoTokenizer
27
- import numpy as np
28
 
29
- labels = ["entails", "contradicts", "neutral"]
30
- model_name_or_path = "persiannlp/mbert-base-parsinlu-snli-entailment"
31
- model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path)
32
- tokenizer = AutoTokenizer.from_pretrained(model_name_or_path,)
33
 
34
 
35
- def model_predict(text_a, text_b):
36
- features = tokenizer( [(text_a, text_b)], padding="max_length", truncation=True, return_tensors='pt')
37
- output = model(**features)
38
- logits = output[0]
39
- probs = torch.nn.functional.softmax(logits, dim=1).tolist()
40
- idx = np.argmax(np.array(probs))
41
- print(labels[idx], probs)
42
 
43
 
44
- model_predict(
45
  "این مسابقات بین آوریل و دسامبر در هیپودروم ولیفندی در نزدیکی باکرکی ، ۱۵ کیلومتری (۹ مایل) غرب استانبول برگزار می شود.",
46
  "در ولیفندی هیپودروم، مسابقاتی از آوریل تا دسامبر وجود دارد."
47
  )
48
 
49
- model_predict(
50
  "آیا کودکانی وجود دارند که نیاز به سرگرمی دارند؟",
51
  "هیچ کودکی هرگز نمی خواهد سرگرم شود.",
52
  )
53
 
54
- model_predict(
55
  "ما به سفرهایی رفته ایم که در نهرهایی شنا کرده ایم",
56
  "علاوه بر استحمام در نهرها ، ما به اسپا ها و سونا ها نیز رفته ایم."
57
  )
5
  thumbnail: "https://upload.wikimedia.org/wikipedia/commons/a/a2/Farsi.svg"
6
  tags:
7
  - entailment
8
+ - mt5
9
  - persian
10
  - farsi
11
  license: "CC BY-NC-SA 4.0"
22
  Here is an example of how you can run this model:
23
 
24
  ```python
25
+ from transformers import MT5ForConditionalGeneration, MT5Tokenizer
 
 
26
 
27
+ model_size="base"
28
+ model_name = f"persiannlp/mt5-{model_size}-parsinlu-snli-entailment"
29
+ tokenizer = MT5Tokenizer.from_pretrained(model_name)
30
+ model = MT5ForConditionalGeneration.from_pretrained(model_name)
31
 
32
 
33
+ def run_model(premise, hypothesis, **generator_args):
34
+ input_ids = tokenizer.encode(f"{premise}<sep>{hypothesis}", return_tensors="pt")
35
+ res = model.generate(input_ids, **generator_args)
36
+ output = tokenizer.batch_decode(res, skip_special_tokens=True)
37
+ print(output)
38
+ return output
 
39
 
40
 
41
+ run_model(
42
  "این مسابقات بین آوریل و دسامبر در هیپودروم ولیفندی در نزدیکی باکرکی ، ۱۵ کیلومتری (۹ مایل) غرب استانبول برگزار می شود.",
43
  "در ولیفندی هیپودروم، مسابقاتی از آوریل تا دسامبر وجود دارد."
44
  )
45
 
46
+ run_model(
47
  "آیا کودکانی وجود دارند که نیاز به سرگرمی دارند؟",
48
  "هیچ کودکی هرگز نمی خواهد سرگرم شود.",
49
  )
50
 
51
+ run_model(
52
  "ما به سفرهایی رفته ایم که در نهرهایی شنا کرده ایم",
53
  "علاوه بر استحمام در نهرها ، ما به اسپا ها و سونا ها نیز رفته ایم."
54
  )