| from transformers import pipeline | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # 7. Text Generation (causal LM β free continuation) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Default model: openai-community/gpt2 | |
| # β Used for: very small & fast English generation (~124M params) | |
| # good for quick testing & prototyping | |
| # | |
| # Modern alternative: mistralai/Mistral-7B-Instruct-v0.3 | |
| # β Used for: much smarter, coherent, instruction-following text | |
| # excellent for creative writing, explanations, code | |
| pipe = pipeline("text-generation", max_new_tokens=70) | |
| # pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3", max_new_tokens=70) | |
| print(pipe("In Ludhiana people love to eat")[0]["generated_text"]) |