Views
No views yet
1from transformers import T5Tokenizer, T5ForConditionalGeneration
2
3model_name = 'doc2query/all-with_prefix-t5-base-v1'
4tokenizer = T5Tokenizer.from_pretrained(model_name)
5model = T5ForConditionalGeneration.from_pretrained(model_name)
6
7prefix = "answer2question"
8text = "Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects."
9
10text = prefix+": "+text
11
12input_ids = tokenizer.encode(text, max_length=384, truncation=True, return_tensors='pt')
13outputs = model.generate(
14 input_ids=input_ids,
15 max_length=64,
16 do_sample=True,
17 top_p=0.95,
18 num_return_sequences=5)
19
20print("Text:")
21print(text)
22
23print("\nGenerated Queries:")
24for i in range(len(outputs)):
25 query = tokenizer.decode(outputs[i], skip_special_tokens=True)
26 print(f'{i + 1}: {query}')model.generate() is non-deterministic. It produces different queries each time you run it.train_script.py in this repository.data_config.json in this repository. Most of the datasets are available at https://huggingface.co/sentence-transformers.| Prefix | Output |
|---|---|
| answer2question | Why should I use python in my business? ; What is the difference between Python and.NET? ; what is the python design philosophy? |
| review2title | Python a powerful and useful language ; A new and improved programming language ; Object-oriented, practical and accessibl |
| abstract2title | Python: A Software Development Platform ; A Research Guide for Python X: Conceptual Approach to Programming ; Python : Language and Approach |
| text2query | is python a low level language? ; what is the primary idea of python? ; is python a programming language? |
data_config.json in this repository.