思路:使用模型的特征提取层,转化成向量,然后比对向量的距离(比如cos)
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
# load model & feature only
model = models.mobilenet_v3_small(pretrained=True)
mode[......]
思路:使用模型的特征提取层,转化成向量,然后比对向量的距离(比如cos)
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
# load model & feature only
model = models.mobilenet_v3_small(pretrained=True)
mode[......]
HuggingFace的transformers库提供了各种SOTA开源模型的方案,而且做了整合链,很方便使用。
1 安装
pip install transformers
2 做情感分析任务
数据准备
from transformers import pipeline
import numpy as np
import pandas as pd
import seaborn as sn
# prepare data
df = pd.read_csv("Airline[......]
device = "cuda" if torch.cuda.is_available() else "cpu"
print(device)
# create data
weight = 0.6
bias = 0.4
start = 0
end = 1
ste[......]