Code Monkey home page Code Monkey logo

question_generation's Introduction

Question Generation using 🤗transformers

Project Details

Question generation is the task of automatically generating questions from a text paragraph. The most straight-forward way for this is answer aware question generation. In answer aware question generation the model is presented with the answer and the passage and asked to generate a question for that answer by considering the passage context. While there are many papers available for QG task, it's still not as mainstream as QA. One of the reasons is most of the earlier papers use complicated models/processing pipelines and have no pre-trained models available. Few recent papers, specifically UniLM and ProphetNet have SOTA pre-trained weights availble for QG but the usage seems quite complicated.

This project is aimed as an open source study on question generation with pre-trained transformers (specifically seq-2-seq models) using straight-forward end-to-end methods without much complicated pipelines. The goal is to provide simplified data processing and training scripts and easy to use pipelines for inference.

Initial experiments

Initial experiments are conducted using the SQuADv1 dataset and T5 model with different input processing formats as described below.

answer aware question generation

For answer aware models the input text can be processed in two ways.

1. prepend format:

Here the answer is simply added before the context and seperated by sep token. For example

42 [SEP] 42 is the answer to life, the universe and everything.

for T5 model the input is processed like this

answer: 42 context: 42 is the answer to life, the universe and everything.

2. highlight format

Here the answer span is highlighted within the text with special highlight tokens.

<hl> 42 <hl> is the answer to life, the universe and everything.

This idea is proposed in the "A Recurrent BERT-based Model for Question Generation" paper. See section 4.3

answer extraction models

As the answer aware models need answers for generating question, we need something which can extract answer like spans from the text. This can be done using various methods like NER, noun-phrase extarction etc. But here a model is trained to extract answer like spans, to see how it'll work. With T5, answer extarction is done using the text-to-format.

As the highlight format will need to know the position of extracted answer spans the input for answer extraction is processed as follows

  1. split the text into senteces.
  2. for each sentence that has answers, highlight the sentence with <hl> tokens.
  3. for the target text join the answers in that sentence with <sep> tokens.

For example for this text

Python is a programming language. Created by Guido van Rossum and first released in 1991.

following examples will be created

Input text: <hl> Python is a programming language. <hl> Created by Guido van Rossum and first released in 1991.

target text: Python <sep>

and

Input text: Python is a programming language. <hl> Created by Guido van Rossum and first released in 1991 <hl>.

target text: Guido van Rossum <sep> 1991 <sep>

At inference time the text is split into sentences and each sentence is highlighted.

Multitask QA-QG

For answer aware question generation we usually need 3 models, first which will extract answer like spans, second model will generate question on that answer and third will be a QA model which will take the question and produce an answer, then we can compare the two answers to see if the generated question is correct or not.

Having 3 models for single task is lot of complexity, so goal is to create a multi-task model which can do all of these 3 tasks

  1. extract answer like spans
  2. generate question based on the answer
  3. QA

T5 model is fine-tuned in multi-task way using task prefixes as described in the paper.

End-to-End question generation (answer agnostic)

In end-to-end question generation the model is aksed to generate questions without providing the answers. This paper discusses these ideas in more detail. Here the T5 model is trained to generate multiple questions simultaneously by just providing the context. The questions are seperated by the <sep> token. Here's how the examples are processed

input text: Python is a programming language. Created by Guido van Rossum and first released in 1991.

target text: Who created Python ? <sep> When was python released ? <sep>

All the training details can be found in this wandb project

Results

Results on the SQuAD1.0 dev set using above approaches. For decoding, beam search with num_beams 4 is used with max decoding length set to 32.

For multitask qa-qg models the EM and F1 scores are privded as QA-EM and QA-F1.

The nlg-eval package is used for calculating the metrics.

Name BLEU-4 METEOR ROUGE-L QA-EM QA-F1 QG-FORMAT
t5-base-qg-hl 21.3226 27.0854 43.5962 - - highlight
t5-base-qa-qg-hl 21.0141 26.9113 43.2484 82.46 90.272 highlight
t5-small-qa-qg-hl 18.9872 25.2217 40.7893 76.121 84.904 highlight
t5-small-qg-hl 18.5921 24.9915 40.1886 - - highlight
t5-small-qg-prepend 18.2791 24.6722 39.958 - - prepend

Requirements

transformers==3.0.0
nltk
nlp==0.2.0 # only if you want to fine-tune.

after installing nltk do

python -m nltk.downloader punkt

Usage

Use the pipeline whch mimics 🤗transformers pipeline for easy inference.

The pipeline is divided into 3 tasks

  1. question-generation: for single task question generation models.
  2. multitask-qa-qg: for multi-task qa,qg models.
  3. e2e-qg: for end-to-end question generation.

Open In Colab

Question Generation

from pipelines import pipeline

nlp = pipeline("question-generation")
nlp("42 is the answer to life, the universe and everything.")
=> [{'answer': '42', 'question': 'What is the answer to life, the universe and everything?'}]

prepend format

nlp = pipeline("question-generation", model="valhalla/t5-small-qg-prepend", qg_format="prepend")
nlp("42 is the answer to life, the universe and everything.")
=> [{'answer': '42 ', 'question': 'What is the answer to life, the universe, and everything?'}]

Multitask QA-QG

nlp = pipeline("multitask-qa-qg")

# to generate questions simply pass the text
nlp("42 is the answer to life, the universe and everything.")
=> [{'answer': '42', 'question': 'What is the answer to life, the universe and everything?'}]

# for qa pass a dict with "question" and "context"
nlp({
    "question": "What is 42 ?",
    "context": "42 is the answer to life, the universe and everything."
})
=> 'the answer to life, the universe and everything'

End-to-end question generation (without answer supervision)

nlp = pipeline("e2e-qg")
nlp("Python is a programming language. Created by Guido van Rossum and first released in 1991.")
=> [
    'What is a programming language?',
    'Who created Python?',
    'When was Python first released?'
]

By default both pipelines will use the t5-small* models, to use the other models pass the path through model paramter.

By default the question-generation pipeline will download the valhalla/t5-small-qg-hl model with highlight qg format. If you want to use prepend format then provide the path to the prepend model and set qg_format to "prepend". For extracting answer like spans it uses valhalla/t5-small-qa-qg-hl model, you can provide a different model through ans_model parameter.

The multitask-qa-qg model is for multitask models which can extract answer like spans, do qg and qa, so it won't need seperate ans_model. By default valhalla/t5-small-qa-qg-hl model is used with highlight format. If you want to use prepend format then provide the path to the prepend model and set qg_format to "prepend"

The e2e-qg pipeline is for end-to-end question generation. These models can generate multiple questions simultaneously without answer supervision. By default it uses valhalla/t5-small-e2e-qg

Fine-tuning

Data processing

To support different data formats the trainer expects pre-processed cached dataset, so you can process the data the way you want. The cached dataset should be saved using torch.save and it should return a dict with source_ids, target_ids, attention_mask keys from __getitem__.

  • source_ids: encoded source text
  • target_ids: encoded target text
  • attention_mask: attention mask for the source_ids

The T2TDataCollator takes care of preparing right input_ids and labels. It also trims the batches dynamically to remove excessive padding tokens, to speed up the training.

The data/squad_multitask containes the modifed SQuAD dataset for answer aware question generation (using both prepend and highlight formats), question answering (text-to-text), answer extraction and end-to-end question generation. This dataset can be loaded using the awesome 🤗nlp library, this makes processing very easy.

To process and cache the dataset use prepare_data.py script. It will load the correct tokenizer depending on the model_type argument. It adds two new tokens <sep> and <hl> to the tokenizer and saves it at {model_type}_qg_tokenizer path. You should pass this tokenizer to the fine-tuning script.

The datasets will be saved in data/ directory. You should provide filenames using train_file_name and valid_file_name arguments.

process data for single task question generation with highlight_qg_format

python prepare_data.py \
    --task qg \
    --model_type t5 \
    --dataset_path data/squad_multitask/ \
    --qg_format highlight_qg_format \
    --max_source_length 512 \
    --max_target_length 32 \
    --train_file_name train_data_qg_hl_t5.pt \
    --valid_file_name valid_data_qg_hl_t5.pt \

process data for multi-task qa-qg with highlight_qg_format

valid_for_qg_only argument is used to decide if the validation set should only contain data for qg task. For my multi-task experiments I used validation data with only qg task so that the eval loss curve can be easly compared with other single task models

python prepare_data.py \
    --task multi \
    --valid_for_qg_only \ 
    --model_type t5 \
    --dataset_path data/squad_multitask/ \
    --qg_format highlight_qg_format \
    --max_source_length 512 \
    --max_target_length 32 \
    --train_file_name train_data_qa_qg_hl_t5.pt \
    --valid_file_name valid_data_qg_hl_t5.pt \

process dataset for end-to-end question generation

python prepare_data.py \
    --task e2e_qg \
    --valid_for_qg_only \ 
    --model_type t5 \
    --dataset_path data/squad_multitask/ \
    --qg_format highlight_qg_format \
    --max_source_length 512 \
    --max_target_length 32 \
    --train_file_name train_data_e2e_qg_t5.pt \
    --valid_file_name valid_data_e2e_qg_t5.pt \

training

Use the run_qg.py script to start training. It uses transformers Trainer class for training the models.

python run_qg.py \
    --model_name_or_path t5-small \
    --model_type t5 \
    --tokenizer_name_or_path t5_qg_tokenizer \
    --output_dir t5-small-qg-hl \
    --train_file_path data/train_data_qg_hl_t5.pt \
    --valid_file_path data/valid_data_qg_hl_t5.pt \
    --per_device_train_batch_size 32 \
    --per_device_eval_batch_size 32 \
    --gradient_accumulation_steps 8 \
    --learning_rate 1e-4 \
    --num_train_epochs 10 \
    --seed 42 \
    --do_train \
    --do_eval \
    --evaluate_during_training \
    --logging_steps 100

or if you want to train it from script or notebook then

from run_qg import run_qg

args_dict = {
    "model_name_or_path": "t5-small",
    "model_type": "t5",
    "tokenizer_name_or_path": "t5_qg_tokenizer",
    "output_dir": "t5-small-qg-hl",
    "train_file_path": "data/train_data_qg_hl_t5.pt",
    "valid_file_path": "data/valid_data_qg_hl_t5.pt",
    "per_device_train_batch_size": 32,
    "per_device_eval_batch_size": 32,
    "gradient_accumulation_steps": 8,
    "learning_rate": 1e-4,
    "num_train_epochs": 10,
    "seed": 42,
    "do_train": True,
    "do_eval": True,
    "evaluate_during_training": True,
    "logging_steps": 100
}

# start training
run_qg(args_dict)

Evaluation

Use the eval.py script for evaluting the model.

python eval.py \
    --model_name_or_path t5-base-qg-hl \
    --valid_file_path valid_data_qg_hl_t5.pt \
    --model_type t5 \
    --num_beams 4 \
    --max_decoding_length 32 \
    --output_path hypothesis_t5-base-qg-hl.txt

This will save the output at {output_path} file.

To calculate the metrics install the nlg-eval package and run

nlg-eval --hypothesis=hypothesis_t5-base-qg-hl.txt --references=data/references.txt --no-skipthoughts --no-glove 

Applications 🚀

  1. A simple Trivia Quiz on topics of your choice -
    Medium article and its Colab Notebook
  2. Autocards, Accelerating learning through machine-generated flashcards

Relevant papers

question_generation's People

Contributors

mrm8488 avatar nrjvarshney avatar patil-suraj avatar priyanksonis avatar tomwilde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

question_generation's Issues

Trained e2e T5 model doesn't quite match you e2e model

Dear @patil-suraj!

This is a wonderul package. Thank you creating it.

I've tried to train a t5 e2e model using your script, but changing a few hyperparameters due to cuda memory issues on colab. I'm seeing good results, but not quite the same as your e2e model. I'm wondering if I need to train longer or change other hyper parmeters.

Here is a colab for the training: https://colab.research.google.com/drive/1xDltBUhUj-ericq-oyhyLIPajfNflJkU?usp=sharing

Parameters to prepare data:

!python prepare_data.py --task e2e_qg --model_type t5
--valid_for_qg_only
--dataset_path data/squad_multitask/
--train_file_name /content/drive/MyDrive/question_generation/data/train.pt
--valid_file_name /content/drive/MyDrive/question_generation/data/valid.pt
--qg_format highlight_qg_format
--max_source_length 512
--max_target_length 32 \

Parameters for training:

args_dict = {
    "model_name_or_path": "t5-small",
    "model_type": "t5",
    "tokenizer_name_or_path": "t5_qg_tokenizer",
    "output_dir": "/content/drive/MyDrive/question_generation/model/t5-e2e-qg",
    "train_file_path": "/content/drive/MyDrive/question_generation/data/train.pt",
    "valid_file_path": "/content/drive/MyDrive/question_generation/data/valid.pt",
    "do_train": True,
    "do_eval": True,
    "evaluate_during_training": True,
    "logging_steps": 1000,
    "learning_rate": 1e-4,
    "num_train_epochs": 10,
}

Testing:

%cd /content/question_generation
from pipelines import pipeline
nlp = pipeline("e2e-qg", model="/content/drive/MyDrive/question_generation/model/t5-e2e-qg")
nlp_orig = pipeline("e2e-qg")
print (nlp(text))
print (nlp_orig(text))
print ('******')
print (nlp(text2))
print (nlp_orig(text2))
print ('******')
print (nlp(text3))
print (nlp_orig(text3))
print ('******')
print (nlp(text4))
print (nlp_orig(text4))

And results:

/content/question_generation
/usr/local/lib/python3.6/dist-packages/transformers/tokenization_t5.py:184: UserWarning: This sequence already has . In future versions this behavior may lead to duplicated eos tokens being added.
f"This sequence already has {self.eos_token}. In future versions this behavior may lead to duplicated eos tokens being added."
['Who created Python?', 'When was Python first released?', "What does Python's design philosophy emphasize with its notable use of whitespace?"]
['Who created Python?', 'When was Python first released?', "What is Python's design philosophy?"]


['Gravity is a natural phenomenon by which all things with mass or energy are brought toward one another?']
['What is the Latin word for gravitas?', 'What does gravity give weight to on Earth?', "The Moon's gravity causes what?", 'Gravity has an infinite range, but its effects become weaker as objects get further away?']


['What is the answer to life, universe and everything?']
['What is the answer to life, universe and everything?']


['Forrest Gump is a slow-witted but kind-hearted man from what state?']
['What is the story about forrest Gump?', 'Who is the slow-witted but kind-hearted man from Alabama?', 'When did Gump witness and influence several historical events in the 20th century?']

++

Any help is much apprecaited!

ValueError: substring not found

I ran the following code on colab:

from pipelines import pipeline
nlp = pipeline("question-generation")

text = """FIO Labs is an independent, privately-owned company with a global reach.
With the agility of a startup and the ability of a conglomerate, we help
businesses understand and adopt Artificial Intelligence & Data Security
technologies in the right framework and help them stay aligned with their
strategic objectives."""

nlp(text)

and I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-fdf5d062d391> in <module>()
----> 1 nlp(text)

1 frames
/content/question_generation/pipelines.py in _prepare_inputs_for_qg_from_answers_hl(self, sents, answers)
    140                 answer_text = answer_text.strip()
    141 
--> 142                 ans_start_idx = sent.index(answer_text)
    143 
    144                 sent = f"{sent[:ans_start_idx]} <hl> {answer_text} <hl> {sent[ans_start_idx + len(answer_text): ]}"

ValueError: substring not found

I don't understand why this error comes when I gave proper text.

This also occurred with

text8 = """Prashanth Bandi is one of the highly regarded consultants in the IT world, he \
is a Technology Evangelist with 18 years of consulting experience dealing with \
diverse problems and delivering technology solutions to complex business \
challenges. His adaptive nature, perseverance and genuine passion for \
technology makes him the torch bearer of our company.
"""

How to get some kind of score for how confident the model is on that question?

Hi First of all thank you for this amazing repo. So much things to learn.
So my question was sometimes model generates some questions which are not grammatically correct maybe becoz of the answer highlighted word it is facing difficulties to form a questions on that. Is there a way to get a confidence score for each question it generates like question answering does?

model confidence score

hi @patil-suraj

currently, i am working with the "valhalla/t5-base-qa-qg-hl" for generating answers against questions.
I have few question here:
How can I print the confidence with which the answer is predicted?
What is the maximum length of passage I can pass for the answers ?

Answer Extraction

Hi @patil-suraj ,

Using the E2E QG model, curious how I can extract the answer span the question was generated for, in this model ?

AssertionErrors

Doing the finetuning and keeping seeing the follow assertion errors

Epoch: 0%| | 0/8 [00:00<?, ?it/s/opt/conda/lib/python3.6/site-packages/nlp/utils/py_utils.py:191: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:141.)
return function(data_struct)
Traceback (most recent call last):
File "./do_training.py", line 34, in
run_qg(args)
File "/workspace/QG/QG/run_qg.py", line 233, in run_qg
main(args_file = "args.json")
File "/workspace/QG/QG/run_qg.py", line 198, in main
model_path = model_args.model_name_or_path if os.path.isdir(model_args.model_name_or_path) else None
File "/opt/conda/lib/python3.6/site-packages/transformers/trainer.py", line 499, in train
tr_loss += self._training_step(model, inputs, optimizer)
File "/workspace/QG/QG/trainer.py", line 36, in _training_step
outputs = model(**inputs)
File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 155, in forward
outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/opt/conda/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 165, in parallel_apply
return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/opt/conda/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 85, in parallel_apply
output.reraise()
File "/opt/conda/lib/python3.6/site-packages/torch/_utils.py", line 395, in reraise
raise self.exc_type(msg)
AssertionError: Caught AssertionError in replica 0 on device 0.
Original Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 60, in _worker
output = module(*input, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/transformers/modeling_t5.py", line 1094, in forward
assert kwargs == {}, f"Unexpected keyword arguments: {list(kwargs.keys())}."
AssertionError: Unexpected keyword arguments: ['return_tuple'].

issue when finetuning with bart for end-to-end question generation ('bart-base' not found)

When we run command for preparing data for e2e qg:

python3 prepare_data.py --task e2e_qg --valid_for_qg_only --model_type bart --dataset_path data/squad_multitask/ --qg_format highlight_qg_format --max_source_length 512 --max_target_length 32 --train_file_name train_data_e2e_qg_bart.pt --valid_file_name valid_data_e2e_qg_bart.pt

it fails with::

01/12/2021 03:17:06 - INFO - transformers.tokenization_utils_base - Model name 'bart-base' not found in model shortcut name list (t5-small, t5-base, t5-large, t5-3b, t5-11b). Assuming 'bart-base' is a path, a model identifier, or url to a directory containing tokenizer files.
Traceback (most recent call last):
File "prepare_data.py", line 204, in
main()
File "prepare_data.py", line 151, in main
tokenizer = T5Tokenizer.from_pretrained("bart-base")
File "/data/priyank/question_generation/venv_qg/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 1140, in from_pretrained
return cls._from_pretrained(*inputs, **kwargs)
File "/data/priyank/question_generation/venv_qg/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 1239, in _from_pretrained
raise EnvironmentError(
OSError: Model name 'bart-base' was not found in tokenizers model name list (t5-small, t5-base, t5-large, t5-3b, t5-11b). We assumed 'bart-base' was a path, a model identifier, or url to a directory containing vocabulary files named ['spiece.model'] but couldn't find such vocabulary files at this path or url.

Using Different Transformer Models

Hi @patil-suraj,

I am trying to implement this solution to another languages but T5 does not support lots of them. Is there any way to use for example BERT to implement same solution? Or what can i do the transform this implementation to using BERT.

Thank you very much!

Couldn't instantiate the backend tokenizer from one of: (1) a `tokenizers` library serialization file, (2) a slow tokenizer instance to convert or (3) an equivalent slow tokenizer class to instantiate and convert. You need to have sentencepiece installed to convert a slow tokenizer to a fast one.

Hello, I used this model to generate question and it worked until 2-3 days ago:
https://huggingface.co/valhalla/t5-base-qg-hl

Now it returns the error message:
Couldn't instantiate the backend tokenizer from one of: (1) a tokenizers library serialization file, (2) a slow tokenizer instance to convert or (3) an equivalent slow tokenizer class to instantiate and convert. You need to have sentencepiece installed to convert a slow tokenizer to a fast one.

For some reason, the sample question works (what is the answer of the universe?), but anything "custom" returns with that message. Here is what I don't understand: the last commit was 5 months ago, so how come the error log appears now?

Here is the sentence I tried inputting:
The bump is made of cartilage
Before I would get error log if the sentence was too long, but now even for short sentences like the above one it wouldn't even work.

Questions generated don't make sense sometimes

I ran the following code on Colab:

text1 = """
Chicken Samosas. Chicken Samosas costs <hl>$6.95<hl>."""

text2 = """
Chicken Samosas has <hl>Crispy Wrappers filled with Spiced Chicken<hl>.
"""

text3 = """
Chicken Samosas is served with <hl>Cilantro Dipping Sauce<hl>.
"""

from transformers import pipeline
from transformers import AutoTokenizer, AutoModelWithLMHead

singletask_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-small-qg-hl")
singletask_model = AutoModelWithLMHead.from_pretrained("valhalla/t5-small-qg-hl")

enc = singletask_tokenizer([text2], return_tensors="pt")
input_ids = enc["input_ids"]
attention_mask = enc["attention_mask"] # necessary if padding is enabled so the model won't attend pad tokens

singletask_tokens = singletask_model.generate(input_ids=input_ids, attention_mask=attention_mask
                                              , num_beams=2, num_return_sequences=2
)

out_ = []
for token in singletask_tokens:
  print(singletask_tokenizer.decode(token))
  out_.append(singletask_tokenizer.decode(token))

Note: I ran the second text.

Output is as follows:

What is assassssssssssss
What is assassasssssssss

They don't make sense. How to generate meaningful questions when we have only one sentence?

When I run first and third text, the outputs are as follows:

text1:
What is the cost of chicken Samosas?
What is the cost of Chicken Samosas?

text3:
What is served with? Chicken Samosas is served with?
What is served with? Chicken Samosas is served with what?

Continuous Question Generation

Hi @patil-suraj ,

Would it be possible to generate new questions for a given document, given previous questions/answers for the same ? I've read some papers in the area but not sure i understand how the preceding qa pairs could help generate newer qa pairs.

Deploy model

Hi,

I'm trying to deploy this model via torch serve. But when i try and save the tokenizer:

tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-base-e2e-qg") tokenizer.save_pretrained('/dummy_location')

it does not save a vocab.txt, instead saving:

'/t5_model/spiece.model', '/t5_model/special_tokens_map.json', '/t5_model/added_tokens.json' '/tokenizer_config.json'

How can i get the vocab.txt to use for deployment / please suggest an alternative method for deployment

Regarding Fine-Tuning

Hey! Awesome work!
I wanted to ask how have you actually fine tune on the SQuAD dataset? I couldn't find it here.
i was trying to understand the valhalla/t5-base-e2e-qg model.

End-to-End Question Generation directly from /trasnformers library

I'm trying to generate questions using "valhalla/t5-base-e2e-qg" End-to-End model directly from the /transformers library.

My code:

# Item No. 1
text1 = "Chicken Samosa costs $6.95"

text2 = "Chicken Samosa has Crispy Wrappers filled with Spiced Chicken."

text3 = "Chicken Samosa is served with Cilantro Dipping Sauce."

t5_e2es_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-small-e2e-qg")
t5_e2es_model = AutoModelWithLMHead.from_pretrained("valhalla/t5-small-e2e-qg")

enc = t5_e2es_tokenizer([text2], return_tensors="pt")
input_ids = enc["input_ids"]
attention_mask = enc["attention_mask"] # necessary if padding is enabled so the model won't attend pad tokens

t5e2es_tokens = t5_e2es_model.generate(input_ids=input_ids, attention_mask=attention_mask
                                              , num_beams=10, num_return_sequences=3
)

out_ = []
for token in t5e2es_tokens:
  print(t5_e2es_tokenizer.decode(token))
  out_.append(t5_e2es_tokenizer.decode(token))

This is the output I get:

Chicken Samosa has Crisp Wrappers filled with Spiced Chicken Samosa has
Chicken Samosa has Crisp Wrappers filled with Spice Chicken Samosa has Crisp
Chicken Samosa has Crisp Wrappers filled with Spiced Chicken. Crisp Wrappers filled

Where did I go wrong? I thought I just had to follow the same procedure which I did for single-task qg model.

training_script in args_dict?

What is training_script here?

args_dict = {
  "num_cores": 8,
  'training_script': 'train_t5_squad.py',
  "model_name_or_path": 't5-base',
  "max_len": 512 ,
  "target_max_len": 16,
  "output_dir": './models/tpu',
  "overwrite_output_dir": True,
  "per_gpu_train_batch_size": 8,
  "per_gpu_eval_batch_size": 8,
  "gradient_accumulation_steps": 4,
  "learning_rate": 1e-4,
  "tpu_num_cores": 8,
  "num_train_epochs": 4,
  "do_train": True
}

Generate exact number of questions

Hi,

Great work on the library 🎉, it's super useful.

Is it possible to generate a specific number of questions ? I know we have 'num_return_sequences' but i've seen that despite specifying specifying a high number of return sequences:

`model_args = {
"max_length": 256,
"num_beams": 12,
"length_penalty": 1.5,
"no_repeat_ngram_size": 3,
"num_return_sequences": 10,
"early_stopping": True,
}

nlp(text5, model_args)`

i still get fewer than expected questions:

['The speed of light is slower in a medium other than what?', 'What is responsible for phenomena such as refraction?', 'The idea of light scattering from, or being absorbed and re-emitted by atoms, is both incorrect and what is not seen in nature?']

Length limitations

I am experiencing a limitation in returned answers:

This is a list of the answers: [['coronavirus testing '], ['it is not necessary for people who don’t feel sick but have been in close contact with infected people to get tested '], ['Centers for Disease Control and Prevention '], ['15 minutes '], ['CDC testing overview page '], ['caveat '], ['those with health problems that make them more likely to suffer severe illness from an infection '], ['U.S. Department of Health and Human Services '], ['to reflect current evidence and the best public health interventions '], ['wearing a mask, staying at least 6 feet apart from others and washing hands '], ['meetings of a White House coronavirus task force '], ['CDC '], ['many people were involved in “lots of editing, lots of input.” '], ['hard to know how much was written by what person '], ['bizarre '], ['testing contacts of infected people '], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]

The full text can be found for testing here: news.txt

I have experienced this on multiple texts, and it seems to stop generating answers after about 16 or 17 (in the range of 2200-2500 characters of the complete text).

Something wrong in the trainer.py?

the keyword argument "prediction_loss_only" doesn't exist?
TypeError: init() got an unexpected keyword argument 'prediction_loss_only'

Sentences with no answers are also extracted

hi, @patil-suraj:
Why is it that sentences with no answers are also extracted when doing the answer generation task?
For example, the input text is "hi, json."
output result is "[{'answer': 'hi, json', 'question': 'What is the name of the name of the name of the name of the name of the name of the name of the name of the name of the name'}]"

Unable to train ProphetNet

Hi,
I'm trying to train e2e QG using microsoft prophetnet. I have changed tokenizer and model. My training runs fine for fist 22 steps but then all of a sudden it stops giving the error 'RuntimeError: CUDA error: device-side assert triggered'

model = ProphetNetForConditionalGeneration.from_pretrained('microsoft/prophetnet-large-uncased-squad-qg')
tokenizer = ProphetNetTokenizer.from_pretrained('microsoft/prophetnet-large-uncased-squad-qg')

Can anyone please help me where else do I have to make changes.
Anyone help would be helpful
Thanks in advance

Optimization warning

Thanks for making this repo!

UserWarning: Seems like `optimizer.step()` has been overridden after learning rate scheduler initialization. Please, make sure to call `optimizer.step()` before `lr_scheduler.step()`. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
  "https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate", UserWarning)

Is this something we should adjust for or is this intentional? I'm also curious as to what hyperparameter tuning has been done. the effective fine-tuning batch size is about 256 (GAS * BS). I'm wondering how that number was arrived at!

Cant it be possible to use text file instead of text assigning in variables!

Hii @patil-suraj .
would anyone tell me how can i use text file containing input passages instead of passing paragraphs separately in variables.Is it possible to do so??

And also Im not getting where is Squad dataset using in this model as using squad dataset it generates thousands of questions at a time but here we are taking text ,then where the use of Squad?

Error at question generation pipeline - non matching answers with original text

My use case is testing this using a few sentences for a few random documents from the newsgroups dataset in each call. In many cases i run to this error:
...site-packages\question_generation\pipelines.py", line 142, in _prepare_inputs_for_qg_from_answers_hl
ans_start_idx = sent.index(answer_text)
ValueError: substring not found

It's actually line 140 - I've added a couple print statements to check what's the case.

What I can see there happening is that the function is checking whether the 'answer' (which was extracted FROM the input sentence in the QGPipeline._extract_answers()) actually EXISTS in the input sentence. I believe this check shouldn't even take place since the answer should be in the sentence. The real problem then is why do the answers sometimes not match themselves as they were in the original text? Also isn't there a better way around it rather than raising an error?

Examples of these values just before line 140 of pipelines.py is run:

  1. Sent: The doctors are not sure exactly why the pain is persisting but feel some sort of nerve damage has occured and they have employed Tylenol 3 and soon Morphine to relieve the pain.
    Answer txt: Tylenol 3 and soon Morphine

The original text has 1 extra space which is not in the 'answer'

  1. Sent: Fact is SCSI-2 controler chips allow near SCSI-2 speeds through a SCSI-1 device {As shown in the Mac Quadra} which skews some of the data of SCSI-1 vs IDE or ESDI test.
    Answer txt: SCSI-2 controler chips

Same as above

Answer like span extraction

Kudos for your great work.
This is not an issue but i wanted to know more about how you are extracting answer like span from the context and then passing it to qg.

How to start?

hey it would be of great help if you would guide us ...in understanding your project ......as the details mentioned in the readme file is bit hard to undertsand.

Questions not generating in a trained model

I am using this notebook to train model
I have following dataset which is different from SQUAD used in the google colab:

{'Answer': 'if the part was ordered from us please contact our customer service department for further assistance.',
 'Answer ID': 5184257,
 'Content Downvotes': 0,
 'Content Moderation Status': 'Posted',
 'Content Upvotes': 0,
 'Product SKU': 'XXXX',
 'Product URL': 'https://www.XXXX.com/XXX/XXXX',
 'Question': 'the magnet that comes with this cover is loose, no instructions on what to glue it on with or its position. Any instructions for this cover ?',
 'context': 'Part Details Includes: Gasket Your DIY Solution - Complete Repair in One Purchase Stop searching for parts individually and complete your repair with a single purchase of a customized kit or set from DIY Solutions. if the part was ordered from us please contact our customer service department for further assistance.',
 'description': "Part Details Includes: Gasket Your DIY Solution - Complete Repair in One Purchase Stop searching for parts individually and complete your repair with a single purchase of a customized kit or set from DIY Solutions. High-Quality Parts From Trusted Brands DIY Solutions' kits and sets are selected from the best automotive brands and include hard-to-find and even obsolete parts you may need for your vehicle. Guaranteed Fit DIY Solutions ensures its selected parts are quality-tested to guarantee fit and function",
 'review': 'Perfect fit speedy delivery Mak June 30, 2017 These guys are awesome!'}

Because of different columns, I have change the function from the colab notebook. It looks like this:

def add_eos_to_examples(example):
    example['input_text'] = 'question: %s  context: %s </s>' % (example['Question'], example['context'])#(example['question'], example['context'])
    example['target_text'] = '%s </s>' % example['Answer']#example['answers']['text'][0]
    return example

When I load the model generated and see the output, I get answer instead of question. What am I doing wrong?

from transformers import T5Tokenizer
tokenizer = T5Tokenizer.from_pretrained('t5-base')

!git clone https://github.com/patil-suraj/question_generation.git
%cd question_generation
from pipelines import pipeline
from transformers import T5ForConditionalGeneration, T5Tokenizer

model = T5ForConditionalGeneration.from_pretrained('../models/tpu').to('cpu') # because its loaded on xla by default
tokenizer = T5Tokenizer.from_pretrained('../models/tpu')
nlp = pipeline('question-generation', model=model, tokenizer=tokenizer, qg_format="prepend")
nlp("42 is the answer to life, the universe and everything.")
>>
[{'answer': '42 ',
  'question': '42 is the answer to life, the universe and everything.'}] #LOOKS ANSWER INSTEAD OF QUESTION

Should have been like following:

from pipelines import pipeline

nlp = pipeline("question-generation")
nlp("42 is the answer to life, the universe and everything.")
=> [{'answer': '42', 'question': 'What is the answer to life, the universe and everything?'}]

GPU OOM

Hi,

this is really great, thx for sharing. As per title I have limited GPU memory, any pointers on getting it to work ok?

thanks again.

AssertionError during question generation.

Hello @patil-suraj,

I get the following assertion error:

Code:

gen = pipeline("question-generation", model='valhalla/t5-base-qg-hl', ans_model='valhalla/t5-base-qa-qg-hl')
qa = gen('Direct calls or provocation to audiences to commit criminal acts should be challenged.')

Error:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1448, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File ".../teaching.py", line 167, in
qa = gen('Direct calls or provocation to audiences to commit criminal acts should be challenged.')
File "...\question_generation\pipelines.py", line 63, in call
questions = self._generate_questions(qg_inputs)
File "...\question_generation\pipelines.py", line 68, in _generate_questions
inputs = self._tokenize(inputs, padding=True, truncation=True)
File "...\question_generation\pipelines.py", line 110, in _tokenize
return_tensors="pt"
File "...\venv\lib\site-packages\transformers\tokenization_utils_base.py", line 1832, in batch_encode_plus
**kwargs,
File "...\venv\lib\site-packages\transformers\tokenization_utils.py", line 554, in _batch_encode_plus
verbose=verbose,
File "...\venv\lib\site-packages\transformers\tokenization_utils.py", line 616, in _batch_prepare_for_model
return_attention_mask=return_attention_mask,
File "...\venv\lib\site-packages\transformers\tokenization_utils_base.py", line 1912, in pad
"You should supply an encoding or a list of encodings to this method. "
AssertionError: You should supply an encoding or a list of encodings to this method. An encoding is the output of one the encoding methods of the tokenizer, i.e. call/encode_plus/batch_encode_plus.

Also note:

ans_start_idx = sent.index(answer_text)

was changed to:

if answer_text in sent:
    ans_start_idx = sent.index(answer_text)
else:
    continue

Speed of model

Hi,

I was wondering if it was possible to do some fine-tuning to make the model run faster ?

Multitask pipeline question

Hi @patil-suraj,
Thank you for this amazing project.
My question regarding the multitask-qa-qg pipeline is whether it simply provides the extra functionality of Question-Answering on demand, or if it actually compares a Question-Answer-generated answer (using the generated question) with the answer-like span that was produced to help generate the question, as part of the pipeline.

If the latter is the case, is it possible to pass it a separate model for the "checking" of the questions (like BERT or RoBERTa)? Or is it better going about using the 'question-generation' pipeline and then checking the questions against those models' predictions?

Also, something odd that I've noticed: Sometimes the model extracts an answer-like span and, although the question generated is of good quality, it does not correspond to the 'answer-span', but a different concept within the sentence, which actually a QA model would predict correctly if asked the question. Here's an example:

Sentence: Note that use of NHS England equipment and networks to participate in social media activities during your own time is covered by the Internet Usage Policy.
Answer-like span: NHS England
Generated question: What policy covers your use of social media?

Although the question is very good, it does not get answered by the 'answer' that was used to produce it in the first place.
The correct answer is: "Internet Usage Policy" which is also predicted correctly by QA models. My point is that even good quality questions may be filtered out, not because of the accuracy of the QA model, but by the poor correlation or the 'answer' span and the generated question.

model.generate on tensorflow converted model is not working

Conversion

model: https://huggingface.co/valhalla/t5-small-e2e-qg
Script: https://github.com/huggingface/transformers/blob/master/src/transformers/convert_pytorch_checkpoint_to_tf2.py

Instead of tf_model.save_weights(tf_dump_path, save_format="h5"), I used tf_model.save_pretrained.

When I used the following script for inference:

from transformers import T5Tokenizer, TFT5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained('valhalla/t5-small-e2e-qg')
model = TFT5ForConditionalGeneration.from_pretrained('save-pretrained')

inputs = tokenizer.batch_encode_plus(['question-generation: Python is a programming language. Created by Guido van Rossum and first released in 1991.'], max_length=64, add_special_tokens=True, truncation=True, padding=False, pad_to_max_length=False, return_tensors="tf")

model.generate(input_ids=inputs['input_ids'],
           #attention_mask=inputs['attention_mask'],
           **{"max_length": 64, "num_beams": 4, "length_penalty": 1.5, "no_repeat_ngram_size": 3, "early_stopping": True,})

I'm encountering the error:

Traceback (most recent call last):
  File "e2e-qg.py", line 10, in <module>
	model.generate(input_ids=inputs['input_ids'],
  File "/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_utils.py", line 909, in generate
	use_cache=use_cache,
  File "/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_utils.py", line 951, in _generate_no_beam_search
	outputs = self(**model_inputs)
  File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in __call__
	outputs = call_fn(inputs, *args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_t5.py", line 1148, in call
	output_hidden_states=output_hidden_states,
  File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in __call__
	outputs = call_fn(inputs, *args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_t5.py", line 616, in call
	mask_seq_length = shape_list(past_key_value_states[0][0])[2] + seq_length
IndexError: list index out of range

Let me know where is the issue or you have any workaround for the same?

ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds

I'm trying to convert the T5 model to torchscript model. While I'm doing that I'm running into this error
You have to specify either decoder_input_ids or decoder_inputs_embed

here's the code :

!pip install -U transformers==3.0.0
!python -m nltk.downloader punkt

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch

model = AutoModelForSeq2SeqLM.from_pretrained('valhalla/t5-base-qg-hl')

t_input =  'Python is a programming language. It is developed by <hl> Guido Van Rossum <hl>. </s>'

tokenizer = AutoTokenizer.from_pretrained('valhalla/t5-base-qg-hl', return_tensors = 'pt')

def _tokenize(
    inputs,
    padding=True,
    truncation=True,
    add_special_tokens=True,
    max_length=64
):
    inputs = tokenizer.batch_encode_plus(
        inputs, 
        max_length=max_length,
        add_special_tokens=add_special_tokens,
        truncation=truncation,
        padding="max_length" if padding else False,
        pad_to_max_length=padding,
        return_tensors="pt"
    )
    return inputs

token = _tokenize(t_input, padding=True, truncation=True)


traced_model = torch.jit.trace(model, [token['input_ids'], token['attention_mask']] )
torch.jit.save(traced_model, "traced_t5.pt")

got this error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-f9b449524ef1> in <module>()
     32 
     33 
---> 34 traced_model = torch.jit.trace(model, [token['input_ids'], token['attention_mask']] )
     35 torch.jit.save(traced_model, "traced_t5.pt")

7 frames
/usr/local/lib/python3.6/dist-packages/transformers/modeling_t5.py in forward(self, input_ids, attention_mask, encoder_hidden_states, encoder_attention_mask, inputs_embeds, head_mask, past_key_value_states, use_cache, output_attentions, output_hidden_states)
    682         else:
    683             if self.is_decoder:
--> 684                 raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
    685             else:
    686                 raise ValueError("You have to specify either input_ids or inputs_embeds")

ValueError: You have to specify either decoder_input_ids or decoder_inputs_embeds

The same issue occurs when converting the model to .oonx model.
how to convert the T5 model to torchscript ? is this the right method, or is there a better way for doing this.

Does this support only SQUAD dataset?

I was wondering if I can simply give any dataset. It looks like it needs questions, answer and context. So I suppose the following dataset for example is sufficient to do training?

questions | answer | context
q1 | a1 | context 1
q2 | a2 | context 2
q3 | a3 | context 3
q4 | a4 | context 4

This way can I train by loading the dataset and leaving rest of the notebook same?

valid_dataset = nlp.load_dataset('csv', data_files='/content/drive/My Drive/context_created.csv', split='train[:10%]')
train_dataset = nlp.load_dataset('csv', data_files='/content/drive/My Drive/context_created.csv', split='train[10%:]')

Unable to create tensor, you should probably activate truncation and/or padding

Getting this error:
"Unable to create tensor, you should probably activate truncation and/or padding "
ValueError: Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' 'truncation=True' to have batched tensors with the same length.

Evan setting 'padding=True' 'truncation=True' is not helping

My whole code is as follows:
`
from pipelines import pipeline

text = "Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace."
nlp = pipeline("e2e-qg")
ques = nlp(text)
`

Multiple answers are highlighted in pipelines.py

Hi, thank you for creating this project.

I was using the pipelines.py and found out that multiple answers are highlighted in the code below:

sent = sents[i]
for answer_text in answer:
sents_copy = sents[:]
answer_text = answer_text.strip()
ans_start_idx = sent.index(answer_text)
sent = f"{sent[:ans_start_idx]} <hl> {answer_text} <hl> {sent[ans_start_idx + len(answer_text): ]}"
sents_copy[i] = sent

If there are more than one extracted answers in each sentence (e.g. [Cochran, John Stamos]), this code produces something like

John Stamos; the character\'s last name in season one was <hl> Cochran <hl>
<hl> John Stamos <hl> ; the character\'s last name in season one was <hl> Cochran <hl>

while I expect the results to be

John Stamos; the character\'s last name in season one was <hl> Cochran <hl>
<hl> John Stamos <hl> ; the character\'s last name in season one was Cochran

Is this an intended behavior? or can I simply move the line 136 (sent = sents[i]) inside the for loop to recover the original sentence for each highlighting? Thank you.

Can't it be possible to use text file instead of passing text in variables.

Hii @patil-suraj ,
would anyone tell me ,how to create input text file for these models,so we dont need to pass text separately in different variables.Is it possible to do so??

And SQuad dataset is a huge dataset ,im not getting why this model is not generating many questions at time bcz while using Squad we can generate thousands of questions at a time,why am i not able to see those questions if this model is using Squad dataset.

Unable to batch input data while finetuning

Hello,

I am trying to finetune the t5 model (e2e_qg) on the squad dataset. I have followed the instructions mentioned in the ReadME file. I had initially prepared the data using prepare_data.py. I checked the dataset manually. It seems to have all the keys i.e source_ids, target_ids and attention mask. However, while running the script run_qg.py, I get the below error.
Can you please help me sort this out?

 File "run_qg.py", line 236, in <module>
    main()
  File "run_qg.py", line 198, in main
    model_path=model_args.model_name_or_path if os.path.isdir(model_args.model_name_or_path) else None
  File "/home/deepayan/.local/lib/python3.7/site-packages/transformers/trainer.py", line 699, in train
    for step, inputs in enumerate(epoch_iterator):
  File "/home/deepayan/miniconda3/envs/pytorch2/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/home/deepayan/miniconda3/envs/pytorch2/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 385, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/home/deepayan/miniconda3/envs/pytorch2/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "/home/deepayan/projects/new_ques_gen/data_collator.py", line 33, in __call__
    input_ids = torch.stack([example['source_ids'] for example in batch])
  File "/home/deepayan/projects/new_ques_gen/data_collator.py", line 33, in <listcomp>
    input_ids = torch.stack([example['source_ids'] for example in batch])
KeyError: 'source_ids'

using question_generation directly from /transformers

Hi,

I'm pretty new to using huggingface/transformers.

I have seen that this repo has an API to play with on huggingface website.

I'm not understanding how to use this directly from the library.

This is my code:

from transformers import pipeline

from transformers import AutoTokenizer, AutoModelWithLMHead

singletask_tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-small-qg-hl")

singletask_model = AutoModelWithLMHead.from_pretrained("valhalla/t5-small-qg-hl")

input_ids = singletask_tokenizer.encode(text)

Now, running this code gives me following error:

singletask_model.generate(input_ids=input_ids)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-0f839014ebe9> in <module>()
----> 1 singletask_model.generate(a)

1 frames
/usr/local/lib/python3.6/dist-packages/transformers/generation_utils.py in generate(self, input_ids, max_length, min_length, do_sample, early_stopping, num_beams, temperature, top_k, top_p, repetition_penalty, bad_words_ids, bos_token_id, pad_token_id, eos_token_id, length_penalty, no_repeat_ngram_size, num_return_sequences, attention_mask, decoder_start_token_id, use_cache, **model_specific_kwargs)
    278 
    279         if input_ids is not None:
--> 280             batch_size = input_ids.shape[0]  # overriden by the input batch_size
    281         else:
    282             batch_size = 1

AttributeError: 'list' object has no attribute 'shape'

How should I go about this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.