|
--- |
|
license: mit |
|
--- |
|
|
|
# TaskToSubtask |
|
## Overview |
|
|
|
This repository contains a Hugging Face NLP model designed to break down long task instructions into smaller, actionable subtasks. The output is a single string where each subtask is separated by a comma. |
|
|
|
## Installation |
|
|
|
To use this model, you'll need to install the transformers library from Hugging Face. You can install it using pip: |
|
``` |
|
pip install sentencepiece |
|
pip install transformers |
|
pip install accelerate -U |
|
``` |
|
|
|
## Usage |
|
To use the Subtask Generator, you can use the following Python code snippet: |
|
```python |
|
import torch |
|
from transformers import T5Tokenizer, T5ForConditionalGeneration, TrainingArguments, Trainer |
|
model = T5ForConditionalGeneration.from_pretrained("Jwizzed/TaskToSubtask").to('cpu') |
|
tokenizer = T5Tokenizer.from_pretrained("t5-small") |
|
|
|
def infer(input_text, model, tokenizer): |
|
model.eval() |
|
input_tensor = tokenizer.encode(input_text, return_tensors="pt").to('cpu') |
|
with torch.no_grad(): |
|
output = model.generate(input_tensor, max_length=1024) |
|
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True) |
|
decoded_output = decoded_output.replace(" and ", ", ").strip() |
|
return decoded_output |
|
|
|
|
|
sample_text = """ |
|
Dear Students |
|
Please watch all class materials for our topic before you answer the following questions. |
|
1. Give your own definition of mental health. |
|
2. What does a person with good mental health look like? |
|
3. How do you deal with your stress? |
|
4. Out of many suggestions to help improve your mental health, which strategies you think most helpful to you? |
|
|
|
Please type your answer. Don’t forget to put your name and ID on the right top cornor. Written in full sentences is preferable than mind map |
|
|
|
Plagiarism/ copying your friends’ answers will be penalized. |
|
""" |
|
|
|
print(infer(sample_text, model.to('cpu'), tokenizer)) |
|
|
|
``` |