你好,很棒的项目!
我注意到当悬停注解变得相当长时,它们的宽度没有限制,变得非常不可用。当我在个人项目中遇到这个问题时,我使用了类似于这样的文本换行,效果很好(这个示例只是为了了解源代码中缺失的内容):
import textwrap
df["wrapped_doc"] = df["doc"].apply(lambda x: '<br>'.join(textwrap.wrap(x, width=60)))
多走一步就是添加一个"header",用于指定悬停时的相关信息,如点索引id、主题的标签等。
你怎么看?
祝你度过愉快的一天
PS:textwrap位于默认的Python库中
5条答案
按热度按时间lndjwyie1#
当你使用
.visualize_documents
可视化主题时,你基本上可以将文档的任何表示传递给函数,因为它们只用于注解(悬停)。所以在将文档传递给函数时,你可以限制它们的长度。话虽如此,默认的textwrap解决方案确实会更好。特别是因为它是一个默认的Python库,这应该会让事情变得容易得多。我可能唯一的担忧是,当你尝试可视化大型数据集(>100_000)时,textwrap是否足够快。然而,可视化超过100_000个文档通常不建议,所以我不确定这是否实际上是一个问题。
标题绝对是一个好主意。当涉及到定义这些自定义悬停时,Plotly非常挑剔,但它应该有可能向函数提供额外的元数据。
旁注:我尝试过用类似bokeh的东西替换plotly,以便在悬停中也显示图像,但不幸的是,这需要进行重大更改。这将允许在悬停期间显示更多信息。
hs1rzwqc2#
仅供参考:
ru9i0ody3#
谢谢,这是一个相当长的文本,这种情况不应该经常发生。然而,如果你有百万份这样的文档,那么处理时间将达到约15分钟,这绝对太长了。
gfttwv5a4#
我好奇地想知道langchain是如何进行拆分的。
我从他们的文档中复制了一堆代码,并删除了测试中不需要的部分,结果令人满意:
(使用
ipython script.py
运行)nzkunb0c5#
感谢您的工作,MaartenGr。
啊,幸好我在自己打开之前找到了这个帖子。我也想把文本 Package 起来,因为它会超出屏幕 :)现在我只是在_documents.py的第105行添加了两行代码。
import textwrap df["doc"] = ['<br>'.join(textwrap.wrap(docs[index],width=80)) for index in indices]
也许您在应用之前检查一下文本长度,因为如果文本很长, Package 仍然没有用处 :)