This is a
doc2query model based on T5 (also known as
docT5query).
1from transformers import T5Tokenizer, T5ForConditionalGeneration
2
3model_name = 'doc2query/all-t5-base-v1'
4tokenizer = T5Tokenizer.from_pretrained(model_name)
5model = T5ForConditionalGeneration.from_pretrained(model_name)
6
7text = "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."
8
9
10input_ids = tokenizer.encode(text, max_length=384, truncation=True, return_tensors='pt')
11outputs = model.generate(
12 input_ids=input_ids,
13 max_length=64,
14 do_sample=True,
15 top_p=0.95,
16 num_return_sequences=5)
17
18print("Text:")
19print(text)
20
21print("\nGenerated Queries:")
22for i in range(len(outputs)):
23 query = tokenizer.decode(outputs[i], skip_special_tokens=True)
24 print(f'{i + 1}: {query}')
This model fine-tuned
google/t5-v1_1-base for 570k training steps. For the training script, see the
train_script.py in this repository.
The input-text was truncated to 384 word pieces. Output text was generated up to 64 word pieces.
This model was trained on a large collection of datasets. For the exact datasets names and weights see the
data_config.json in this repository. Most of the datasets are available at
https://huggingface.co/sentence-transformers.
This model was trained
without a prefix. In contrast to
doc2query/all-with_prefix-t5-base-v1 you cannot specify what type of transformation (answer2question, review2title) etc. you will have. This can lead to a mixture of output values.