Getting Started with OFASys: A Multi-Modal Multi-Task Learning System

May 15, 2022 | Data Science

Welcome to the world of OFASys! If you’re eager to dive into multi-modal tasks that are declarative, modular, and scalable, this guide will provide you everything you need to get started with this robust framework.

What is OFASys?

OFA-Sys is like a Swiss Army knife for machine learning tasks, capable of managing various data modalities and task types with ease. It simplifies multi-modal tasks enabling users to:

  • Quickly introduce new multi-modal tasks by defining a simple one-line instruction.
  • Develop or reuse existing components specific to each modality.
  • Jointly train multiple tasks without the hassle of manually processing multi-modal data.

Currently, OFASys supports seven modalities and more than 20 classes of tasks, including text analysis, image classification, video captioning, and more.

Installation

The installation of OFASys is straightforward. You can choose between two methods: Pip and Source Installation.

Install with Pip

To install OFASys using pip, run:

pip install http://ofasys.oss-cn-zhangjiakou.aliyuncs.com/pkg/ofasys-0.1.0-py3-none-any.whl

To check if the installation was successful, use:

python -c "import ofasys"

Install from Source (Optional)

If you wish to customize your training tasks, clone the OFASys repository:

git clone https://github.com/OFA-Sys/OFA-Sys.git
cd OFASys
python setup.py develop

Training One Model for All Tasks

To define tasks for training, you will need to create multiple tasks simultaneously. This is similar to being a conductor leading different sections of an orchestra to produce a harmonious piece.

from ofasys import Task, Trainer, GeneralistModel

task1 = Task(
    name='caption',
    instruction=['IMAGE:image_url] what does the image describe? - [TEXT:caption]'],
    micro_batch_size=4,
)

task2 = Task(
    name='text_infilling',
    instruction='what is the complete text of [TEXT:sentence, mask_ratio=0.3]? - [TEXT:sentence]',
    micro_batch_size=2,
)

As depicted above, each task has a clear instruction that tells OFASys what to do with the provided data. Tasks are defined like setting the character line in a play, clarifying their role in the grand performance.

Setting Up Datasets

Utilizing a dataset with OFASys is as easy as pie! You can load datasets via Huggingface Dataset or customize your own.

from datasets import load_dataset

task1.add_dataset(load_dataset('TheFusion21PokemonCards')['train'], 'train')
task2.add_dataset(load_dataset('glue', 'cola')['train'], 'train')

In these lines, we are adding datasets to our tasks much like adding ingredients to a recipe. The final outcome depends on how well you select and combine these ingredients!

Infer Multiple Multi-modal Tasks with One Checkpoint

Once your model is trained, inferencing can be done using a single checkpoint, akin to having a one-stop shop for all your needs!

from ofasys import OFASys
model = OFASys.from_pretrained('multitask.pt')

Then simply create and run your instructions just like in our previous examples, but this time leveraging the knowledge captured in the checkpoint.

Troubleshooting

If you encounter any issues during installation or usage, here are some common troubleshooting tips:

  • Ensure that you have the required versions of PyTorch (1.8.0) and Python (3.7) installed on your machine.
  • If you’re having issues with audio features, make sure the soundfile library is properly installed.
  • If you are unable to run `import ofasys` successfully, check the installation directory to ensure it installed correctly.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Learn More

For further guidance, refer to the:

Happy coding with OFASys!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox