Lesson 4 of 8Article19 min
NLP and Computer Vision Essentials
NLP and Computer Vision Essentials
Natural Language Processing (NLP)
- Text classification: spam, sentiment, intent.
- Entity extraction: names, dates, amounts.
- Question answering and summarization.
Computer Vision
- Image classification predicts a label for an image.
- Object detection finds and localizes multiple objects.
- Segmentation predicts per-pixel categories.
Image classification prediction sketch
import torch
from torchvision import models, transforms
from PIL import Image
model = models.resnet18(weights="IMAGENET1K_V1")
model.eval()
img = Image.open("sample.jpg")
tensor = transforms.ToTensor()(img).unsqueeze(0)
with torch.no_grad():
logits = model(tensor)
pred_class = logits.argmax(dim=1).item()