chatchat-space / Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain
Apache License 2.0
31.23k stars 5.45k forks source link

使用UnstructuredWordDocumentLoader,load数据后,loader.load报错 #3482

Closed Meteorslxy closed 5 months ago

Meteorslxy commented 5 months ago

问题描述 / Problem Description 在conda env 中 python=3.9 执行pip langchain后 执行下述代码,报出错误 loader = UnstructuredWordDocumentLoader("***.docx",mode="elements") documents = loader.load()

[nltk_data] Error loading punkt: <urlopen error [Errno 99] Cannot [nltk_data] assign requested address>

但是在相同环境下,执行下述代码,却运行正常 loader = TextLoader('./***.txt') documents = loader.load()

环境信息 / Environment Information

dosubot[bot] commented 5 months ago

你好,@Meteorslxy!很高兴再次见到你。希望你最近一切都好。

您遇到的问题可能是由于在处理Word文档与处理纯文本文件时涉及的操作和依赖项不同。TextLoader可能直接加载文本数据,无需复杂的解析或外部库。

在您的RapidOCRDocLoader中,该过程涉及几个步骤和外部库,这些可能是错误的来源:

  1. 使用python-docx解析文档:加载器使用python-docx解析Word文档。错误可能源于文档元素的错误处理,或者文档的结构本身不符合预期。

  2. 使用PILRapidOCR提取图像和OCR:从文档中提取嵌入的图像并使用OCR处理它们引入了可能的故障点,特别是如果OCR库遇到不支持的图像格式或无法正确初始化。

  3. 处理复杂文档结构:您的加载器试图处理文档中的文本和表格元素。在遍历这些元素的逻辑中可能会出现错误,特别是如果文档包含复杂的嵌套结构。

  4. 依赖项和环境:使用外部库,如PILnumpyrapidocr_onnxruntime,意味着错误也可能源于这些依赖项的问题,如安装问题,版本不兼容,或这些库中的运行时错误。

没有具体的错误消息或追溯,很难确定确切的原因。然而,需要调查的常见问题包括:

要诊断和修复问题,首先隔离过程的每个部分(文档解析,图像提取,OCR),并确保每个部分都与您的文档单独工作。然后,逐步整合它们,同时在每个步骤中处理可能的错误。

参考源码:

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
Meteorslxy commented 5 months ago

你好,再尝试多种方法后,还是报错。 [nltk_data] Error loading punkt: <urlopen error [Errno 99] Cannot[nltk_data] assign requested address>

LookupError: 
**********************************************************************
  Resource punkt not found.
  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('punkt')

  For more information see: https://www.nltk.org/data.html

  Attempted to load tokenizers/punkt/PY3/english.pickle

尝试安装punkt也不可以。

Meteorslxy commented 5 months ago

应该是网络问题,从https://github.com/nltk/nltk_data,下载【packages】 ,然后把【packages】 文件夹名换成 :【nltk_data】,放在【/root/nltk_data】,最后把【tokenizers】文件夹下的【punkt.zip】进行解压,即可使用