Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Multi-Task Learning with use_all_task #3453

Open
zrjohnnyl opened this issue May 10, 2024 · 0 comments
Open

[Question]: Multi-Task Learning with use_all_task #3453

zrjohnnyl opened this issue May 10, 2024 · 0 comments
Labels
question Further information is requested

Comments

@zrjohnnyl
Copy link

Question

How can I correctly train two tasks simultaneously on a single corpus using the parameter use_all_task=True? When I attempted to train two models together on one corpus, I encountered a RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn.

multitask_dataset = CONLL_03_DUTCH()
tasks = ['ner', 'pos']
model_1 = initialize_tagger(multitask_dataset, shared_embedding, tasks[0])
model_2 = initialize_tagger(multitask_dataset, shared_embedding, tasks[1])
multitask_model = MultitaskModel([model_1, model_2], use_all_tasks=True, task_ids=tasks)
trainer = ModelTrainer(multitask_model, multitask_dataset)
trainer.fine_tune('resources/taggers/sota-ner-flert',
learning_rate=5.0e-6,
max_epochs=20)
╭─────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────╮
│ in :60 │
│ │
│ ❱ 60 trainer.fine_tune('resources/taggers/sota-ner-flert', │
│ │
│ /pyzr/active_venv/lib/python3.10/site-packages/flair/trainers/trainer.py:253 in fine_tune │
│ │
│ ❱ 253 │ │ return self.train_custom( │
│ │
│ /pyzr/active_venv/lib/python3.10/site-packages/flair/trainers/trainer.py:606 in train_custom │
│ │
│ ❱ 606 │ │ │ │ │ │ │ self._backward(scaler.scale(loss)) │
│ │
│ /pyzr/active_venv/lib/python3.10/site-packages/flair/trainers/trainer.py:124 in _backward │
│ │
│ ❱ 124 │ │ loss.backward() │
│ │
│ /pyzr/active_venv/lib/python3.10/site-packages/torch/_tensor.py:487 in backward │
│ │
│ ❱ 487 │ │ torch.autograd.backward( │
│ │
│ /pyzr/active_venv/lib/python3.10/site-packages/torch/autograd/init.py:200 in backward │
│ │
│ ❱ 200 │ Variable._execution_engine.run_backward( # Calls into the C++ engine to run the bac │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

@zrjohnnyl zrjohnnyl added the question Further information is requested label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant