DLAI Logo
AI is the new electricity and will transform and improve nearly all areas of human lives.

Welcome back!

We'd like to know you better so we can create more relevant courses. What do you do for work?

DLAI Logo
  • Explore Courses
  • Community
    • Forum
    • Events
    • Ambassadors
    • Ambassador Spotlight
  • My Learnings
  • daily streak fire

    You've achieved today's streak!

    Complete one lesson every day to keep the streak going.

    Su

    Mo

    Tu

    We

    Th

    Fr

    Sa

    free pass got

    You earned a Free Pass!

    Free Passes help protect your daily streak. Complete more lessons to earn up to 3 Free Passes.

    Free PassFree PassFree Pass
Hi, in this lesson, you will be translating text from English to French and summarizing long documents and using open source models from Meta. Let's get started. For this classroom, the libraries have already been installed for you. If you are running this on your own machine, you can install the Transformers library by running the following. pip install transformers Similarly, you can install PyTorch by running the following. pip install torch Since the libraries are already installed in this classroom, I won't run these commands. Let's import the pipeline function from Transformers and also import torch. Now that the pipeline is imported, we can create the translator pipeline by typing translator equals to pipeline. We need to set the task to be equal to translation. And we need to set the model. For this particular task, we will select a model from Meta. This model from Meta and NLLB stands for No Language Left Behind. It is capable of translating 200 different languages. The last argument we will add is the torch D type. We will set it to torch BFloat 16. By setting the torch D type to BFloat 16, we are able to compress the model without any performance degradation. pip install BFloat 16 Now that the translator is loaded, we can start to translate text. So, the text that we will be translating is the following... To translate the text, you can pass the text to the translator. You also can set the source language, and target language, just like that. The source language is English, so you need to pass the following string. As for the target language, we said that we will be translating the text to French, so we need to pass this string. For each language, you have a specific string that you need to pass to the translator. You can find the code for each language at the following link. Let's check the translated text. As you can see, the text has been successfully translated into French. If you know a little bit about French, you can see that puppy was correctly translated to chiot, but there are still a few mistakes that were made. As you can see, llama was translated as lamme, which is wrong. It should have been just llama. Now, I invite you to stop the video and try yourself with your own text or by changing the target language. Before moving to the summarization task, let's free some memory by deleting the model and calling the garbage collector To do that, we need to import GC. We need to delete the translator. And we need to call GC.collect. Summarization is also very simple to perform using pipeline. You just need to set task as summarization. Let's do that. To perform the summarization, we will use a model from Mela called BART-Large-CNN. Lastly, we will also set the Torch D type to Bfloat16 to compress the model. Now that the summarizer pipeline is loaded, let's summarize the following text. As you can see, the following text is a description about Paris. And let's put that into our pipeline. To get the summary, you just need to pass to the summarizer tool that we just loaded the text. You can also set the minimum length and the maximum length of the summary just by setting the minimum length and max length arguments. So, in our example, we set it the minimum length and the maximum length arguments. So, in our example, we set it the minimum length 10 and the maximum length to 100. Let's see what we get. And as you can see, we indeed have the summary of the text we passed earlier. Now, I encourage you to pause the video here and try to summarize some other piece of text that you find on the Internet. Or maybe even summarize an email. In the next lesson, you will measure the similarity between any two sentences. This task is very useful for many applications that involve searching for relevant pieces of text. Let's go on to the next lesson.
course detail
DLAI Logo
AI is the new electricity and will transform and improve nearly all areas of human lives.
LearnCode
Next Lesson
Open Source Models with Hugging Face
  • Introduction
    Video
    ・
    5 mins
  • Selecting models
    Video
    ・
    5 mins
  • Natural Language Processing (NLP)
    Video with Code Example
    ・
    9 mins
  • Translation and Summarization
    Video with Code Example
    ・
    5 mins
  • Sentence Embeddings
    Video with Code Example
    ・
    5 mins
  • Zero-Shot Audio Classification
    Video with Code Example
    ・
    9 mins
  • Automatic Speech Recognition
    Video with Code Example
    ・
    15 mins
  • Text to Speech
    Video with Code Example
    ・
    2 mins
  • Object Detection
    Video with Code Example
    ・
    11 mins
  • Image Segmentation
    Video with Code Example
    ・
    16 mins
  • Image Retrieval
    Video with Code Example
    ・
    7 mins
  • Image Captioning
    Video with Code Example
    ・
    5 mins
  • Multimodal Visual Question Answering
    Video with Code Example
    ・
    4 mins
  • Zero-Shot Image Classification
    Video with Code Example
    ・
    6 mins
  • Deployment
    Video with Code Example
    ・
    11 mins
  • Conclusion
    Video
    ・
    1 mins
  • Course Feedback
  • Community
  • 0%