danyaljj commited on
Commit
4ebd0af
1 Parent(s): 46e7773

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +26 -7
README.md CHANGED
@@ -22,25 +22,44 @@ This is a wikibert-based model for multiple-choice question answering.
22
  Here is an example of how you can run this model:
23
 
24
  ```python
 
 
25
  from transformers import AutoConfig, AutoModelForMultipleChoice, AutoTokenizer
26
 
27
  model_name = "persiannlp/wikibert-base-parsinlu-multiple-choice"
28
  tokenizer = AutoTokenizer.from_pretrained(model_name)
29
  config = AutoConfig.from_pretrained(model_name)
30
- model = AutoModelForMultipleChoice.from_pretrained(model_name, config = config)
31
 
32
 
33
- def run_model(input_string):
34
- input_ids = tokenizer.encode(input_string, return_tensors="pt")
35
- output = model(input_ids)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  print(output)
37
  return output
38
 
39
 
40
- run_model("وسیع ترین کشور جهان کدام است؟ <sep> آمریکا <sep> کانادا <sep> روسیه <sep> چین")
41
- run_model("طامع یعنی ؟ <sep> آزمند <sep> خوش شانس <sep> محتاج <sep> مطمئن")
42
  run_model(
43
- "زمینی به ۳۱ قطعه متساوی مفروض شده است و هر روز مساحت آماده شده برای احداث، دو برابر مساحت روز قبل است.اگر پس از (۵ روز) تمام زمین آماده شده باشد، در چه روزی یک قطعه زمین آماده شده <sep> روز اول <sep> روز دوم <sep> روز سوم <sep> هیچکدام")
 
44
 
45
  ```
46
 
22
  Here is an example of how you can run this model:
23
 
24
  ```python
25
+ from typing import List
26
+ import torch
27
  from transformers import AutoConfig, AutoModelForMultipleChoice, AutoTokenizer
28
 
29
  model_name = "persiannlp/wikibert-base-parsinlu-multiple-choice"
30
  tokenizer = AutoTokenizer.from_pretrained(model_name)
31
  config = AutoConfig.from_pretrained(model_name)
32
+ model = AutoModelForMultipleChoice.from_pretrained(model_name, config=config)
33
 
34
 
35
+ def run_model(question: str, candicates: List[str]):
36
+ assert len(candicates) == 4, "you need four candidates"
37
+ choices_inputs = []
38
+ for c in candicates:
39
+ text_a = "" # empty context
40
+ text_b = question + " " + c
41
+ inputs = tokenizer(
42
+ text_a,
43
+ text_b,
44
+ add_special_tokens=True,
45
+ max_length=128,
46
+ padding="max_length",
47
+ truncation=True,
48
+ return_overflowing_tokens=True,
49
+ )
50
+ choices_inputs.append(inputs)
51
+
52
+ input_ids = torch.LongTensor([x["input_ids"] for x in choices_inputs])
53
+ output = model(input_ids=input_ids)
54
  print(output)
55
  return output
56
 
57
 
58
+ run_model(question="وسیع ترین کشور جهان کدام است؟", candicates=["آمریکا", "کانادا", "روسیه", "چین"])
59
+ run_model(question="طامع یعنی ؟", candicates=["آزمند", "خوش شانس", "محتاج", "مطمئن"])
60
  run_model(
61
+ question="زمینی به ۳۱ قطعه متساوی مفروض شده است و هر روز مساحت آماده شده برای احداث، دو برابر مساحت روز قبل است.اگر پس از (۵ روز) تمام زمین آماده شده باشد، در چه روزی یک قطعه زمین آماده شده ",
62
+ candicates=["روز اول", "روز دوم", "روز سوم", "هیچکدام"])
63
 
64
  ```
65