加载 spacy 模型会减慢我的单元测试的运行速度。有没有办法模拟 spacy 模型或 Doc 对象来加速单元测试?
当前缓慢测试的示例
import spacy
nlp = spacy.load("en_core_web_sm")
def test_entities():
text = u"Google is a company."
doc = nlp(text)
assert doc.ents[0].text == u"Google"
Run Code Online (Sandbox Code Playgroud)
根据文档,我的方法是
手动构建 Vocab 和 Doc 并将实体设置为元组。
from spacy.vocab import Vocab
from spacy.tokens import Doc
def test()
alphanum_words = u"Google Facebook are companies".split(" ")
labels = [u"ORG"]
words = alphanum_words + [u"."]
spaces = len(words) * [True]
spaces[-1] = False
spaces[-2] = False
vocab = Vocab(strings=(alphanum_words + labels))
doc = Doc(vocab, words=words, spaces=spaces) …Run Code Online (Sandbox Code Playgroud) 由于 celery 的可靠性和调度问题,我们决定评估替代方案。我一直在努力在两个消息队列解决方案之间建立一个关于基本性能的基准。
我目前的方法是在两个不同的队列中放置 1000 个任务(获取 nvie.com 并计算网站上的字数),并测量 4 celery(20 秒)与 4 rq 工人(70 秒)的速度。我的代码是https://github.com/swarchris8/celery-vs-rq-benchmark我通过命令行运行 celery,通过 Mac 上的主管运行 rq,从 vagrant 文件中可以清楚地看到 rq 的 Ubuntu 运行指令。
Celery 的性能要好得多,我不确定我测量队列清除速度的测试设置是否存在用于测量任务吞吐量的缺陷。我也在使用默认的 RQ 工人,我怀疑它可能会慢得多。
我的方法是在吞吐量方面对两个消息队列系统进行基准测试的正确方法吗?你采取了哪些方法?celery 比 RQ 快这么多吗?
我想使用自定义 Docker 映像运行 Python Google Cloud Dataflow 作业。
根据文档,这应该是可能的:https://beam.apache.org/documentation/runtime/environments/#testing-customized-images
为了尝试此功能,我使用此公共存储库中的文档中的命令行选项设置了基本字数示例管道https://github.com/swarchris8/beam_wordcount_with_docker
我可以使用 PortableRunner 在本地使用apachebeam/python3.6_sdk图像运行字数统计作业,但使用 Dataflow 我无法执行此操作。
我正在尽可能密切地关注 PortableRunner 的文档,我的参数是:
python -m wordcount --input wordcount.py \
--output counts \
--runner=PortableRunner \
--job_endpoint=embed \
--environment_config=apachebeam/python3.6_sdk
Run Code Online (Sandbox Code Playgroud)
对于数据流:
python -m wordcount --input wordcount.py \
--output gs://healx-pubmed-ingestion-tmp/test/wordcount/count/count \\
--runner=DataflowRunner \
--project=healx-pubmed-ingestion \
--job_name=dataflow-wordcount-docker \
--temp_location=gs://healx-pubmed-ingestion-tmp/test/wordcount/tmp \
--experiment=beam_fn_api \
--sdk_location=/Users/chris/beam/sdks/python/container/py36/build/target/apache-beam.tar.gz \
--worker_harness_container_image=apachebeam/python3.6_sdk \
--region europe-west1 \
--zone europe-west1-c
Run Code Online (Sandbox Code Playgroud)
有关完整详细信息,请参阅链接的存储库。
我在这里做错了什么,或者 Dataflow 中的 Python 作业不支持此功能?
我正在尝试从 React 中的 API 渲染 html 响应。
我认为问题可能是我没有正确处理异步获取。我不确定从 BE 获取的 html 字符串是承诺还是字符串。当我在下面记录它时,我得到一个Promise
我使用这个答案中的代码dangerouslySetInnerHTML来渲染 html,尽管我不确定这是否是渲染完整页面的正确方法。backendHtmlString 是一个完整的页面,我只想将其添加到 React 中。
App.js- 渲染 html 的 React 代码:
async function createMarkup() {
let response;
response = await fetch(`http://localhost:8000/backed_api/html_response/?user_email=chriss%40comtura.ai`)
const backendHtmlString = response.text()
console.log(backendHtmlString)
return {__html: backendHtmlString};
}
function MyComponent() {
return <div dangerouslySetInnerHTML={createMarkup()} />;
}
function App() {
return (
<div className="App">
<MyComponent/>
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import …Run Code Online (Sandbox Code Playgroud) 我无法按照以下说明使用 wordcount 示例创建自定义 Google Cloud Dataflow 模板:https : //cloud.google.com/dataflow/docs/guides/templates/creating-templates
我收到与无法访问 RuntimeValueProvider 相关的错误。我究竟做错了什么?
我的主要功能wordcount.py:
"""A word-counting workflow."""
from __future__ import absolute_import
import argparse
import logging
import re
from past.builtins import unicode
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
from apache_beam.metrics import Metrics
from apache_beam.metrics.metric import MetricsFilter
from apache_beam.options.pipeline_options import PipelineOptions, GoogleCloudOptions
from apache_beam.options.pipeline_options import SetupOptions
class WordExtractingDoFn(beam.DoFn):
"""Parse each line of input text into words."""
def __init__(self):
self.words_counter = Metrics.counter(self.__class__, 'words')
self.word_lengths_counter = …Run Code Online (Sandbox Code Playgroud) apache-beam ×2
celery ×1
docker ×1
javascript ×1
performance ×1
python ×1
python-3.6 ×1
python-3.x ×1
python-rq ×1
reactjs ×1
spacy ×1
unit-testing ×1