r1ck commited on
Commit
a5df5dc
1 Parent(s): b5a310f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md CHANGED
@@ -1,3 +1,82 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: vi
3
+ widget:
4
+ - text: >-
5
+ Python (phát âm tiếng Anh: /ˈpaɪθɑːn/) là một ngôn ngữ lập trình bậc cao cho
6
+ các mục đích lập trình đa năng, do Guido van Rossum tạo ra và lần đầu ra mắt
7
+ vào năm 1991. Python được thiết kế với ưu điểm mạnh là dễ đọc, dễ học và dễ
8
+ nhớ. Python là ngôn ngữ có hình thức rất sáng sủa, cấu trúc rõ ràng, thuận
9
+ tiện cho người mới học lập trình và là ngôn ngữ lập trình dễ học; được dùng
10
+ rộng rãi trong phát triển trí tuệ nhân tạo. Cấu trúc của Python còn cho phép
11
+ người sử dụng viết mã lệnh với số lần gõ phím tối thiểu. Vào tháng 7 năm
12
+ 2018, van Rossum đã từ chức lãnh đạo trong cộng đồng ngôn ngữ Python sau 30
13
+ năm làm việc.
14
  license: apache-2.0
15
+ pipeline_tag: text2text-generation
16
  ---
17
+
18
+ # doc2query-viT5
19
+
20
+ This is a [doc2query](https://arxiv.org/abs/1904.08375) model based on [viT5](https://huggingface.co/VietAI/vit5-base)
21
+
22
+ It can be used for:
23
+ - **Document expansion**: You generate for your paragraphs 20-40 queries and index the paragraphs and the generates queries in a standard BM25 index like Elasticsearch, OpenSearch, or Lucene. The generated queries help to close the lexical gap of lexical search, as the generate queries contain synonyms. Further, it re-weights words giving important words a higher weight even if they appear seldomn in a paragraph.
24
+ - **Domain Specific Training Data Generation**: It can be used to generate training data to learn an embedding model.
25
+
26
+ ## Usage
27
+ ```python
28
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
29
+ import torch
30
+
31
+ model_name = 'doc2query/msmarco-vietnamese-mt5-base-v1'
32
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
33
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
34
+
35
+ text = "Python (phát âm tiếng Anh: /ˈpaɪθɑːn/) là một ngôn ngữ lập trình bậc cao cho các mục đích lập trình đa năng, do Guido van Rossum tạo ra và lần đầu ra mắt vào năm 1991. Python được thiết kế với ưu điểm mạnh là dễ đọc, dễ học và dễ nhớ. Python là ngôn ngữ có hình thức rất sáng sủa, cấu trúc rõ ràng, thuận tiện cho người mới học lập trình và là ngôn ngữ lập trình dễ học; được dùng rộng rãi trong phát triển trí tuệ nhân tạo. Cấu trúc của Python còn cho phép người sử dụng viết mã lệnh với số lần gõ phím tối thiểu. Vào tháng 7 năm 2018, van Rossum đã từ chức lãnh đạo trong cộng đồng ngôn ngữ Python sau 30 năm làm việc."
36
+
37
+
38
+ def create_queries(para):
39
+ input_ids = tokenizer.encode(para, return_tensors='pt')
40
+ with torch.no_grad():
41
+ # Here we use top_k / top_k random sampling. It generates more diverse queries, but of lower quality
42
+ sampling_outputs = model.generate(
43
+ input_ids=input_ids,
44
+ max_length=64,
45
+ do_sample=True,
46
+ top_p=0.95,
47
+ top_k=10,
48
+ num_return_sequences=5
49
+ )
50
+
51
+ # Here we use Beam-search. It generates better quality queries, but with less diversity
52
+ beam_outputs = model.generate(
53
+ input_ids=input_ids,
54
+ max_length=64,
55
+ num_beams=5,
56
+ no_repeat_ngram_size=2,
57
+ num_return_sequences=5,
58
+ early_stopping=True
59
+ )
60
+
61
+
62
+ print("Paragraph:")
63
+ print(para)
64
+
65
+ print("\nBeam Outputs:")
66
+ for i in range(len(beam_outputs)):
67
+ query = tokenizer.decode(beam_outputs[i], skip_special_tokens=True)
68
+ print(f'{i + 1}: {query}')
69
+
70
+ print("\nSampling Outputs:")
71
+ for i in range(len(sampling_outputs)):
72
+ query = tokenizer.decode(sampling_outputs[i], skip_special_tokens=True)
73
+ print(f'{i + 1}: {query}')
74
+
75
+ create_queries(text)
76
+
77
+ ```
78
+
79
+ **Note:** `model.generate()` is non-deterministic for top_k/top_n sampling. It produces different queries each time you run it.
80
+
81
+ ## Training
82
+ This model fine-tuned [VietAI/vit5-base](https://huggingface.co/VietAI/vit5-base) on 30k vietnamese passage-question pairs