Getting Started with Towhee: A Guide to Unstructured Data Processing

Aug 12, 2023 | Data Science

Welcome to the world of Towhee, a powerful framework crafted to optimize the handling of unstructured data with the magic of Large Language Models (LLM). Whether tackling lengthy texts, images, audio, or video, Towhee promises to transform your data processing experiences. Let us embark on this journey to harness the prowess of Towhee!

What is Towhee?

Towhee serves as a cutting-edge solution for orchestrating data processing pipelines, enabling the extraction of meaningful insights from a diverse array of unstructured data types. Its capabilities hinge on two essential aspects:

  • Multi Modalities: Capable of processing images, videos, text, audio files, and even molecular structures.
  • LLM Pipeline Orchestration: Offers flexibility in adapting to various Large Language Models and facilitates local hosting of open-source models.

Core Concepts

Understanding Towhee’s architecture will help you appreciate its functionality:

  • Operators: The fundamental building blocks that process data through deep learning models or Python functions.
  • Pipelines: Interlinked operators forming a Directed Acyclic Graph (DAG) to enable complex functionalities.
  • DataCollection API: A method-chaining API to build custom pipelines for processing various data types rapidly.
  • Engine: Drives data flow among operators and monitors task scheduling and compute resource usage.

Installation

To get started with Towhee, ensure your Python version is 3.7 or higher, and run:

pip install towhee towhee.models

Implementing Pre-defined Pipelines

Towhee provides several ready-to-use pipelines that allow you to implement functionalities effortlessly. Some notable pipelines include:

An Analogy for Understanding Towhee’s Code

Imagine Towhee as a chef in a bustling kitchen. Each recipe (pipeline) calls for different ingredients (data types) to create a delicious dish (processed result). The chef (Towhee) uses various tools (operators) such as knives (data processing methods) and mixers (deep learning models) to slice, puree, and combine the ingredients seamlessly.

Creating Custom Pipelines

If the pre-defined pipelines do not fit your requirements, you can create custom pipelines using Towhee’s Python API. Below is an example of building a cross-modal retrieval pipeline using CLIP:

from towhee import ops, pipe, DataCollection

p = (pipe.input(file_name)
    .map(file_name, img, ops.image_decode.cv2())
    .map(img, vec, ops.image_text_embedding.clip(model_name=clip_vit_base_patch32, modality=image))
    .map(vec, vec, ops.towhee.np_normalize())
    .map((vec, file_name), (), ops.ann_insert.faiss_index(.faiss, 512))
    .output())

for f_name in [“https://raw.githubusercontent.com/towhee-io/towhee/main/assets/dog1.png”,   
                “https://raw.githubusercontent.com/towhee-io/towhee/main/assets/dog2.png”,   
                “https://raw.githubusercontent.com/towhee-io/towhee/main/assets/dog3.png”]:
    p(f_name)

# Flush faiss data into disk.
p.flush()

# search image by text
decode = ops.image_decode.cv2(rgb)
p = (pipe.input(text)
    .map(text, vec, ops.image_text_embedding.clip(model_name=clip_vit_base_patch32, modality=text))
    .map(vec, vec, ops.towhee.np_normalize())
    .map(vec, row, ops.ann_search.faiss_index(.faiss, 3))
    .map(row, images, lambda x: [decode(item[2][0]) for item in x])
    .output(text, images))

DataCollection(p(“puppy Corgi”)).show()

Troubleshooting Tips

While navigating your Towhee journey, you may encounter some hurdles. Here are a few troubleshooting tips:

  • Installation Issues: Ensure that you have the correct version of Python and all dependencies properly installed.
  • Pipeline Errors: Double-check the configuration settings in your pipeline; a small typo can lead to failures.
  • Performance Concerns: If pipelines run slower than expected, consider optimizing by reviewing your data handling techniques or utilizing the GPU.

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

Conclusion

Towhee is a versatile tool that equips developers to streamline the processing of various unstructured data types seamlessly. The comprehensive functionalities it offers can greatly enhance productivity and ease of use, making it a vital part of any AI developer’s toolkit. 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.

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

Tech News and Blog Highlights, Straight to Your Inbox