प्रि-ट्रेन्ड LLMs का उपयोग

Python में LLMs का परिचय

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

Language understanding

डेस्क पर बैठे व्यक्ति के चारों ओर टेक्स्ट क्लासीफिकेशन, समरीकरण, सेंटिमेंट एनालिसिस, और प्रश्न-उत्तर दर्शाते कई टास्क

Python में LLMs का परिचय

Language generation

डेस्क पर बैठे व्यक्ति के चारों ओर टेक्स्ट जेनरेशन और ट्रांसलेशन दर्शाते कई टास्क

Python में LLMs का परिचय

टेक्स्ट जेनरेशन

generator = pipeline(task="text-generation", model="distilgpt2")

prompt = "The Gion neighborhood in Kyoto is famous for"

output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id)
  • सुसंगत
  • सार्थक
  • मानव-सदृश टेक्स्ट
  • eos_token_id: end-of-sequence टोकन ID
Python में LLMs का परिचय

टेक्स्ट जेनरेशन

दो सीक्वेंस का चित्रण: we should go, i really like to travel. टोकन IDs शामिल हैं और जहाँ पैडिंग और EOS है, वह दिखता है

  • pad_token_id: max_length तक अतिरिक्त स्पेस भरता है
  • Padding: टोकन जोड़ना
  • generator.tokenizer.eos_token_id सेट करने पर अर्थपूर्ण टेक्स्ट का अंत चिह्नित होता है, जो ट्रेनिंग से सीखा गया है
  • मॉडल max_length या pad_token_id तक जनरेट करता है
  • truncation = True
Python में LLMs का परिचय

टेक्स्ट जेनरेशन

generator = pipeline(task="text-generation", model="distilgpt2")

prompt = "The Gion neighborhood in Kyoto is famous for"

output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id)

print(output[0]["generated_text"])
The Gion neighborhood in Kyoto is famous for its many colorful green forests, such as the 
Red Hill, the Red River and the Red River. The Gion neighborhood is home to the world's 
tallest trees.
  • अगर प्रॉम्प्ट अस्पष्ट हो तो आउटपुट कमतर हो सकता है
Python में LLMs का परिचय

आउटपुट को निर्देशित करना

generator = pipeline(task="text-generation", model="distilgpt2")


review = "This book was great. I enjoyed the plot twist in Chapter 10." response = "Dear reader, thank you for your review." prompt = f"Book review:\n{review}\n\nBook shop response to the review:\n{response}"
output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id) print(output[0]["generated_text"])
Dear reader, thank you for your review. We'd like to thank you for your reading!
Python में LLMs का परिचय

भाषा अनुवाद

  • Hugging Face पर ट्रांसलेशन टास्क और मॉडल्स की पूरी सूची है
translator = pipeline(task="translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")

text = "Walking amid Gion's Machiya wooden houses was a mesmerizing experience."
output = translator(text, clean_up_tokenization_spaces=True)
print(output[0]["translation_text"])
Caminar entre las casas de madera Machiya de Gion fue una experiencia fascinante.
Python में LLMs का परिचय

अभ्यास करते हैं!

Python में LLMs का परिचय

Preparing Video For Download...