尽管上述两种方法都提供了更好的分数以更好地接近预测,但仍然优选交叉熵.是在每种情况下还是有一些特殊情况我们更喜欢交叉熵而不是MSE?
machine-learning backpropagation neural-network mean-square-error cross-entropy
当 FastAPI 端点发生异常时,我尝试使用后台任务生成日志:
from fastapi import BackgroundTasks, FastAPI
app = FastAPI()
def write_notification(message=""):
with open("log.txt", mode="w") as email_file:
content = f"{message}"
email_file.write(content)
@app.post("/send-notification/{email}")
async def send_notification(email: str, background_tasks: BackgroundTasks):
if "hello" in email:
background_tasks.add_task(write_notification, message="helloworld")
raise HTTPException(status_code=500, detail="example error")
background_tasks.add_task(write_notification, message="hello world.")
return {"message": "Notification sent in the background"}
Run Code Online (Sandbox Code Playgroud)
但是,不会生成日志,因为根据此处和此处的文档,后台任务“仅”在return执行语句后运行。
有什么解决方法吗?
pytorch文章中已经描述了这两个函数之间的区别:log_softmax和softmax有什么区别?
是:exp(x_i) / exp(x).sum()
,日志softmax是:log(exp(x_i) / exp(x).sum())。
但是对于下面的Pytorch代码,为什么会得到不同的输出:
>>> it = autograd.Variable(torch.FloatTensor([0.6229,0.3771]))
>>> op = autograd.Variable(torch.LongTensor([0]))
>>> m = nn.Softmax()
>>> log = nn.LogSoftmax()
>>> m(it)
Variable containing:
`0.5611 0.4389`
[torch.FloatTensor of size 1x2]
>>>log(it)
Variable containing:
-0.5778 -0.8236
[torch.FloatTensor of size 1x2]
Run Code Online (Sandbox Code Playgroud)
但是,值log(0.5611)为-0.25095973129,log(0.4389)为-0.35763441915
为什么会有这样的差异?
我有一个跨多个索引的搜索查询。要根据文档启用此功能,我需要提供一个以逗号分隔的索引列表。
但是当我尝试这样做时: es.search(index='index1,index2',body=body)
我没有得到任何结果:
{u'hits': {u'hits': [], u'total': 0, u'max_score': None}, u'_shards': {u'successful': 10, u'failed': 0, u'skipped': 0, u'total': 10}, u'took': 1, u'timed_out': False}
但是, index='_all' 可以搜索所有索引。我在这里做错了什么还是这个功能有问题?谢谢。
我必须找到具有字符串的匹配文档,例如:在某些“键”范围内的字符串:“ sky”。当我编写单独的匹配和范围查询时,我从ES获得输出,但是合并在一起时会抛出异常。
范围查询:
res = es.search(index="dummy",
body={"from":0, "size":0,"query": {"range":{"key":{"gte":"1000"}}}})
Run Code Online (Sandbox Code Playgroud)
匹配查询:
res = es.search(index="dummy",
body={"from":0, "size":0,"query": {"match":{"word":"sky"}}})
Run Code Online (Sandbox Code Playgroud)
组合查询:
res = es.search(index="dummy",
body={
"from":0,
"size":0,
"query": {
"range":{
"key":{"gte":"1000"}
}
},
"match":{"word":"sky"}
})
Run Code Online (Sandbox Code Playgroud)
组合查询在执行时会引发错误:
引发HTTP_EXCEPTIONS.get(状态码,TransportError)(状态码,error_message,Additional_info)elasticsearch.exceptions.RequestError:TransportError(400,u'parsing_exception',u'[match]中START_OBJECT的未知键。')
合并两个查询的正确方法是什么?