Skip to content

Instantly share code, notes, and snippets.

classifier = pipeline("zero-shot-classification")
text_to_classify = "I love my new blender! It makes smoothies so smooth."
candidate_labels = ["electronics", "kitchen appliance", "sports equipment", "furniture"]
result3 = classifier(text_to_classify, candidate_labels)
print(result3)
classifier = pipeline("sentiment-analysis")
text = "I love sunny days."
result = classifier(text)
text2 = "I don't like the rain."
result2 = classifier(text2)
print("\n=== Sentiment Analysis ===")
print(result)
generator = pipeline("text-generation", model="gpt2")
prompt = "Explain how self-driving cars work in simple terms."
result = generator(prompt, max_length=50, num_return_sequences=1)
print("=== Text Generation ===")
print(result[0]['generated_text'])
from transformers import pipeline
pip uninstall torch
pip install torch --index-url https://download.pytorch.org/whl/cpu
python3 -c "import numpy; print(numpy.__version__)"
pip install transformers torch
pip install "numpy<2"
const nlpTools = require('natural');
const wordStore = ['cat', 'dog', 'elephant', 'giraffe'];
const typoChecker = new nlpTools.Spellcheck(wordStore);
console.log(typoChecker.getCorrections('elephnt', 2));
console.log(typoChecker.getCorrections('grffe', 2));