活动介绍
file-type

构建语义搜索引擎:Transformers与Faiss结合使用

版权申诉
5星 · 超过95%的资源 | 25.47MB | 更新于2025-08-05 | 201 浏览量 | 2 下载量 举报 1 收藏
download 限时特惠:#11.90
在这个部分,我将从给定的文件信息中提取相关的知识点,并展开详细说明。 ### 标题知识点 标题《使用Transformers 和 Faiss 构建语义搜索引擎_Jupyter_python》涉及了几个关键IT知识点。 1. **Transformers**: Transformers是Hugging Face推出的一个开源库,它提供了一系列预训练模型,这些模型基于Transformer架构。Transformer模型是一种深度学习模型,特别擅长处理序列数据,常用于自然语言处理(NLP)任务。预训练模型可以进行微调,以适应特定的任务或数据集,例如文本分类、命名实体识别、问题回答等。 2. **Faiss**: Faiss是由Facebook AI Research开发的库,主要用于高效的相似性搜索和密集向量聚类。它特别适合处理大规模数据集,能够加速构建基于向量相似性的搜索引擎。 3. **语义搜索引擎**: 语义搜索引擎指的是能够理解搜索查询的意图,而不仅仅是匹配关键词的一种搜索引擎。它通过理解查询和文档内容的语义信息,提供更准确的搜索结果。 4. **Jupyter**: Jupyter是一种开源的Web应用程序,允许用户创建和共享包含实时代码、方程、可视化和解释性文本的文档。它支持多种编程语言,如Python,常用于数据清理和转换、数值模拟、统计建模、机器学习等活动。 ### 描述知识点 描述部分提供了两个主要知识点。 1. **构建语义搜索引擎**: 这通常涉及将文本数据转化为向量表示(使用Transformers等模型)并利用Faiss等工具进行高效相似性搜索。整个过程可能包含预处理文本、使用预训练模型提取文本向量表示、建立索引以及查询处理和结果检索。 2. **使用Streamlit和Docker在AWS Elastic Beanstalk上部署机器学习模型**: 这里描述了机器学习模型的部署流程,涉及的几个技术点包括Streamlit、Docker和AWS Elastic Beanstalk。 - **Streamlit**: 是一个开源库,用于创建和分享漂亮的机器学习Web应用。它可以帮助开发者快速将Python脚本转换成交互式的Web应用。 - **Docker**: 是一个开源的应用容器引擎,可以将应用及其依赖打包成一个轻量级、可移植的容器,实现应用的快速部署和环境一致性。 - **AWS Elastic Beanstalk**: 是AWS提供的一个用于简化Web应用和AWS服务部署的应用管理平台,可以处理部署的细节,允许开发者专注于应用的开发。 ### 标签知识点 从标签《python 搜索引擎 jupyter 综合资源 开发语言》中,我们可以得到以下知识点。 1. **Python**: 是一种广泛用于数据科学、机器学习、网络开发等领域的高级编程语言。它具有强大的库生态,如NumPy、Pandas、Matplotlib和SciPy等,以及专门为机器学习设计的库,例如TensorFlow和PyTorch。 2. **搜索引擎**: 不仅指百度、谷歌等网络搜索服务,还包括能够处理数据并根据查询返回相关结果的任何系统或应用。在IT领域,构建搜索引擎通常意味着使用特定的算法来索引数据并快速检索信息。 3. **Jupyter**: 作为标签,意味着在这个上下文中,Jupyter笔记本可能被用于开发和测试搜索引擎模型的原型。 4. **综合资源**: 可能指本教程涉及的知识点较为全面,既包括了NLP和搜索技术,也包括了模型部署和Web应用开发。 5. **开发语言**: 通常指的是编程语言,此处特指Python语言,它是开发此类语义搜索引擎和机器学习模型的首选语言。 ### 压缩包子文件的文件名称列表知识点 从提供的【压缩包子文件的文件名称列表】中的"vector_enginster"来看,我们可以推测以下知识点。 1. **向量引擎(vector engine)**: 这指的是用于处理和搜索向量数据的系统。在这种情况下,它可能是一个搜索工具,用于对预先计算的向量索引进行查询,这些向量索引代表了文档、句子或单词的语义嵌入。 2. **文件名称** : "vector_enginster" 可能表示了该压缩包内包含的文件或资源与构建向量搜索引擎有关,例如预处理脚本、索引文件、模型参数等。 通过将上述知识点整合,我们可以构建一个综合的视图,即开发一个语义搜索引擎需要掌握Python编程、了解NLP技术、熟悉Transformers库和Faiss工具,并能够将模型进行有效的部署。而这些步骤,都可以通过Jupyter笔记本进行有效的开发和测试。

相关推荐

filetype

(smol-env) [heng2@localhost ~]$ python smoldocling_test.py /home/heng2/smol-env/lib/python3.8/site-packages/huggingface_hub/file_download.py:797: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`. warnings.warn( Traceback (most recent call last): File "/home/heng2/smol-env/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py", line 945, in from_pretrained config_class = CONFIG_MAPPING[config_dict["model_type"]] File "/home/heng2/smol-env/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py", line 647, in __getitem__ raise KeyError(key) KeyError: 'idefics3' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "smoldocling_test.py", line 21, in <module> model = AutoModelForVision2Seq.from_pretrained( File "/home/heng2/smol-env/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py", line 523, in from_pretrained config, kwargs = AutoConfig.from_pretrained( File "/home/heng2/smol-env/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py", line 947, in from_pretrained raise ValueError( ValueError: The checkpoint you are trying to load has model type `idefics3` but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.

filetype

2025-06-13 18:54:07,509 [INFO] 使用本地模型路径: ./models 2025-06-13 18:54:07,511 [INFO] 模型目录内容: ['pytorch_model.bin', 'config.json', 'tokenizer_config.json', 'vocab.txt'] 2025-06-13 18:54:07,516 [INFO] 读取训练数据... 2025-06-13 18:54:07,774 [INFO] 训练数据样本数: 55 2025-06-13 18:54:07,780 [INFO] 训练集大小: 44, 验证集大小: 11 2025-06-13 18:54:07,782 [INFO] 创建多任务模型... 2025-06-13 18:54:07,784 [INFO] 正在加载基础模型... --------------------------------------------------------------------------- ValueError Traceback (most recent call last) File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:708, in getattribute_from_module(module, attr) 707 try: --> 708 return getattribute_from_module(transformers_module, attr) 709 except ValueError: File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:712, in getattribute_from_module(module, attr) 711 else: --> 712 raise ValueError(f"Could not find {attr} in {transformers_module}!") ValueError: Could not find BertModel in <module 'transformers' from '/opt/conda/lib/python3.11/site-packages/transformers/__init__.py'>! During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) Cell In[10], line 275 273 # 创建模型 274 logging.info("创建多任务模型...") --> 275 model = MultiTaskModel(num_labels_dict) 277 # 6. 自定义训练循环(简化版) 278 device = torch.device("cuda" if torch.cuda.is_available() else "cpu") Cell In[10], line 107, in MultiTaskModel.__init__(self, num_labels_dict) 105 # 直接从本地加载模型 106 logging.info("正在加载基础模型...") --> 107 self.base_model = AutoModel.from_pretrained(MODEL_PATH, local_files_only=True) 108 logging.info("基础模型加载成功") 110 # 为每个特征构建分类头 File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:568, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 564 return model_class.from_pretrained( 565 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs 566 ) 567 elif type(config) in cls._model_mapping.keys(): --> 568 model_class = _get_model_class(config, cls._model_mapping) 569 if model_class.config_class == config.sub_configs.get("text_config", None): 570 config = config.get_text_config() File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:388, in _get_model_class(config, model_mapping) 387 def _get_model_class(config, model_mapping): --> 388 supported_models = model_mapping[type(config)] 389 if not isinstance(supported_models, (list, tuple)): 390 return supported_models File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:774, in _LazyAutoMapping.__getitem__(self, key) 772 if model_type in self._model_mapping: 773 model_name = self._model_mapping[model_type] --> 774 return self._load_attr_from_module(model_type, model_name) 776 # Maybe there was several model types associated with this config. 777 model_types = [k for k, v in self._config_mapping.items() if v == key.__name__] File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:788, in _LazyAutoMapping._load_attr_from_module(self, model_type, attr) 786 if module_name not in self._modules: 787 self._modules[module_name] = importlib.import_module(f".{module_name}", "transformers.models") --> 788 return getattribute_from_module(self._modules[module_name], attr) File /opt/conda/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:710, in getattribute_from_module(module, attr) 708 return getattribute_from_module(transformers_module, attr) 709 except ValueError: --> 710 raise ValueError(f"Could not find {attr} neither in {module} nor in {transformers_module}!") 711 else: 712 raise ValueError(f"Could not find {attr} in {transformers_module}!") ValueError: Could not find BertModel neither in <module 'transformers.models.bert' from '/opt/conda/lib/python3.11/site-packages/transformers/models/bert/__init__.py'> nor in <module 'transformers' from '/opt/conda/lib/python3.11/site-packages/transformers/__init__.py'>!