【问题标题】:Python Progress Bar for non-iterable process用于不可迭代进程的 Python 进度条
【发布时间】:2022-01-16 20:12:22
【问题描述】:

我正在使用这个Notebook,其中Apply DocumentClassifier部分更改如下。

Jupyter Labs,内核:conda_mxnet_latest_p37

tqdm 是一个进度条包装器。它似乎在for loopsCLI 上都有效。但是,我想在线使用它:

classified_docs = doc_classifier.predict(docs_to_classify)

这是一个迭代过程,但在引擎盖之下。

如何将 tqdm 应用于此行?


代码单元:

doc_dir = "GRIs/"  # contains 2 .pdfs

with open('filt_gri.txt', 'r') as filehandle:
    tags = [current_place.rstrip() for current_place in filehandle.readlines()]


doc_classifier = TransformersDocumentClassifier(model_name_or_path="cross-encoder/nli-distilroberta-base",
                                                task="zero-shot-classification",
                                                labels=tags,
                                                batch_size=2)

# convert to Document using a fieldmap for custom content fields the classification should run on
docs_to_classify = [Document.from_dict(d) for d in docs_sliding_window]

# classify using gpu, batch_size makes sure we do not run out of memory
classified_docs = doc_classifier.predict(docs_to_classify)

【问题讨论】:

  • 如果这不可能,有什么替代方案适合我的情况?

标签: python-3.x jupyter-lab tqdm


【解决方案1】:

基于此TDS Article;所有 Python 进度条库都使用 for loops。假设,我可以更改 predict() 函数并将其附加到那里,但这只是太多的工作。

注意:如果确实有针对非迭代“可访问” 进程的解决方案,我很乐意删除此答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2019-05-16
    相关资源
    最近更新 更多