Embedding Model

term_id: embedding_model

Category: application_paradigms

Definition

这些模型将高维数据映射到低维连续向量空间中,其中相似的项目彼此靠得更近。这种转换捕捉了语义关系,使得…(原文截断)

Summary

嵌入模型将文本或图像等原始数据转换为表示语义意义的稠密数值向量。

Key Concepts

  • 向量表示
  • 语义相似度
  • 降维
  • 特征提取

Use Cases

  • 构建语义搜索引擎
  • 产品或内容推荐系统
  • 聚类相似的文档或图像

Code Example

1
2
3
4
5
6
7
from transformers import AutoTokenizer, AutoModel
import torch

model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
inputs = tokenizer('Hello world', return_tensors='pt')
embeddings = model(**inputs).last_hidden_state.mean(dim=1)