小编Dav*_*cco的帖子

在Visual Studio代码中构建项目时,如何指定目标体系结构?

我是VS code/F#的新手(如果这很傻,那就是preapologies),我正在尝试构建一个F#控制台应用程序(在Windows工作站和我的Linux计算机上).

我和FAKE一起安装了Ionide扩展.

我正在考虑的代码是Iris示例(请参阅如何将介绍ML.Net演示转换为F#?),使用Ionide创建一个新的F#项目并使用Microsoft.ML.

我的iris.fsproj

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
    <DebugType>portable</DebugType>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="iris.fs" />
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="..\.paket\Paket.Restore.targets" />
</Project>
Run Code Online (Sandbox Code Playgroud)

运行脚本时(我使用"播放"按钮,也就是F#:运行VS Code/Ionide提供的脚本),我得到:

C:\Users\MyUser\.nuget\packages\microsoft.ml\0.2.0\build\Microsoft.ML.targets(16,5): error : Microsoft.ML currently supports 'x64' processor architectures. Please ensure your application is targeting 'x64'.

和...一起

Running build failed. Error: System.Exception: dotnet build failed

如何使用Ionide提供的项目结构来定位x64?

f# f#-fake visual-studio-code ionide ml.net

6
推荐指数
1
解决办法
430
查看次数

如何将两个 PyTorch 量化张量矩阵相乘?

我是张量量化的新手,并尝试做一些简单的事情

import torch
x = torch.rand(10, 3)
y = torch.rand(10, 3)

x@y.T
Run Code Online (Sandbox Code Playgroud)

使用在 CPU 上运行的PyTorch量化张量。我因此尝试

scale, zero_point = 1e-4, 2
dtype = torch.qint32
qx = torch.quantize_per_tensor(x, scale, zero_point, dtype)
qy = torch.quantize_per_tensor(y, scale, zero_point, dtype)

qx@qy.T # I tried...
Run Code Online (Sandbox Code Playgroud)

..并得到了错误

运行时错误:无法使用来自“QuantizedCPUTensorId”后端的参数运行“aten::mm”。'aten::mm' 仅适用于这些后端:[CUDATensorId、SparseCPUTensorId、VariableTensorId、CPUTensorId、SparseCUDATensorId]。

是不支持矩阵乘法,还是我做错了什么?

quantization matrix-multiplication pytorch

6
推荐指数
1
解决办法
814
查看次数

如何对 pandas 数据框中的字符串进行词形还原?

我有一个 Python Pandas 数据框,我需要对其中两列中的单词进行词形还原。我正在使用 spacy 来实现这一点。

import spacy
nlp = spacy.load("en")
Run Code Online (Sandbox Code Playgroud)

我正在尝试基于此示例使用词形还原(效果非常好):

doc3 = nlp(u"this is spacy lemmatize testing. programming books are more better than others")
for token in doc3: 
    print (token, token.lemma, token.lemma_)
Run Code Online (Sandbox Code Playgroud)

我已经重写了它以循环遍历数据框中一列的每一行:

for row in example['col1']:
    for token in row:
        print(token.lemma_)
Run Code Online (Sandbox Code Playgroud)

这是可行的,但是,我无法弄清楚如何用词形还原的单词替换 col1 中的单词。

我已经尝试过,它不会返回错误,但也不会替换任何单词。知道出了什么问题吗?

for row in example['col1']:
    for token in row:
        token = token.lemma_
Run Code Online (Sandbox Code Playgroud)

python lemmatization pandas spacy

5
推荐指数
1
解决办法
5510
查看次数

在F#中运行ML.Net Iris演示时,我是否使用TextLoader错误?

我是F#/ .NET的新手,我正在尝试运行如何将介绍ML.Net演示转换为F#的接受答案中提供的F#示例使用ML.NET库,在Visual Studio上使用F#,使用Microsoft.ML(0.2.0).

在构建它时,我得到了错误 error FS0039: The type 'TextLoader' is not defined.

为了避免这种情况,我添加了这一行

open Microsoft.ML.Data
Run Code Online (Sandbox Code Playgroud)

来源.然而,然而,线

pipeline.Add(new TextLoader<IrisData>(dataPath,separator = ","))
Run Code Online (Sandbox Code Playgroud)

触发: error FS0033: The non-generic type 'Microsoft.ML.Data.TextLoader' does not expect any type arguments, but here is given 1 type argument(s)

改为:

pipeline.Add(new TextLoader(dataPath,separator = ","))
Run Code Online (Sandbox Code Playgroud)

收益率: error FS0495: The object constructor 'TextLoader' has no argument or settable return property 'separator'. The required signature is TextLoader(filePath: string) : TextLoader.

改为:

pipeline.Add(new TextLoader(dataPath))
Run Code Online (Sandbox Code Playgroud)

使构建成功,但代码在运行时失败 ArgumentOutOfRangeException: Column …

f# ml.net

5
推荐指数
1
解决办法
484
查看次数

如何从 FastAPI 端点返回字典 + 图像?

我正在尝试使用 FastAPI 来允许我的(dockerized)服务器响应返回的 API 调用

  • 一个图像image,以及
  • 一本字典additional_dict

(对于机器学习示例,这可能是来自分类器和显着性图的分类标签)。

就我而言,我认为使用相同的端点来获取两个对象是有意义的,因为它们是通过相同的计算生成的。

我可以使用/sf/answers/3913353601/的内容成功返回二进制图像:

from PIL import Image
from fastapi import FastAPI, File
import tempfile
from starlette.responses import FileResponse

@app.post("/getstuff")
async def get_image_and_data(file: bytes = File(...)):
    
    image, additional_dict = process_image(image)

    with tempfile.NamedTemporaryFile(mode="w+b", suffix=".png", delete=False) as outfile:
        image.save(outfile)
        return FileResponse(outfile.name, media_type="image/png")
Run Code Online (Sandbox Code Playgroud)

当我通过 上的 swagger UI 调用服务时,这甚至允许我看到图像响应localhost:8000/docs

但是,我不知道如何将图像二进制和字典放在一起。

我尝试将我的 return 语句替换为:

return FileResponse(outfile.name, media_type="image/png"), additional_dict
Run Code Online (Sandbox Code Playgroud)

但这并没有真正起作用(当在 localhost:8000/docs 上尝试 swagger 时,我只是得到下面的 json 回复,其中包含创建的临时文件的路径)

[{
"path": "/tmp/tmpldwe_79d.png",
"status_code": 200,
"filename": …
Run Code Online (Sandbox Code Playgroud)

python fastapi

5
推荐指数
1
解决办法
7356
查看次数

如何在 cookiecutter 模板上运行黑色格式?

我正在使用预提交blackflake8钩子。

error: cannot format在尝试对以下代码进行黑色格式化时得到了这个

from {{cookiecutter.project_name}} import my_module
Run Code Online (Sandbox Code Playgroud)

无论如何,是否有指示黑色,跳过/忽略特定于 cookiecutter 的语法?

python pre-commit cookiecutter python-black

5
推荐指数
0
解决办法
804
查看次数

底层连接已被linkedin关闭

我们有一个运行 .Net Framework 4.6.1 的应用程序,它可以访问对端点的 Linkedin 调用:

https://www.linkedin.com/oauth/v2/accessToken
Run Code Online (Sandbox Code Playgroud)

它一直工作到 2020/07/14 之后,它开始在我们所有的环境中失败,并出现以下错误:

发送请求时发生错误。底层连接已关闭:发送时发生意外错误。无法从传输连接读取数据:现有连接已被远程主机强行关闭。现有连接已被强行关闭通过远程主机

我们一直在运行一些测试,我们发现可以在 PowerShell 中使用以下命令重现错误:

Invoke-WebRequest -Uri https://www.linkedin.com
Run Code Online (Sandbox Code Playgroud)

经过一番研究,我们意识到我们可以使用以下命令强制 PowerShell 使用 TLS 1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)

但它在我们的 IIS 服务器中不起作用。在其他没有安装 IIS 的服务器中,该命令可以正常工作,我们可以正确访问 Linkedin URL。

我们还尝试在 C# 中执行相同的操作,结果相同:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Run Code Online (Sandbox Code Playgroud)

似乎错误与Tls12有关,所以我们开始用Wireshark查看,我们发现在HELLO之后的握手期间连接被重置: Wireshark 日志

你好的相关部分是:

Handshake Protocol: Client Hello
    Handshake Type: Client Hello (1)
    Length: 153
    Version: TLS 1.2 (0x0303)
    Random: 5f1536566faf9700973045f3e502909a269ec62f2df23243…
    Session ID Length: 0
    Cipher Suites Length: 32
    Cipher Suites (16 suites)
        Cipher Suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (0xc028)
        Cipher Suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (0xc027)
        Cipher Suite: …
Run Code Online (Sandbox Code Playgroud)

c# powershell linkedin tls1.2

5
推荐指数
1
解决办法
842
查看次数

如何使用在Docker容器中运行的python脚本创建(dockerized)Elasticsearch索引?

我正在尝试使用从脚本调用的Python客户端https://github.com/elastic/elasticsearch-py(也在容器中运行)为容器化的Elasticsearch db编制索引。
通过查看现有的代码片段,看来这docker-compose是用于我的目的的有用工具。我的目录结构是

  • docker-compose.yml
  • indexer
    • Dockerfile
    • indexer.py
    • requirements.txt
  • elasticsearch
    • Dockerfile

我的docker-compose.yml读物

version: '3'

services:
  elasticsearch:
    build: elasticsearch/
    ports: 
      - 9200:9200
    networks:
      - deploy_network
    container_name: elasticsearch

  indexer:
    build: indexer/
    depends_on:
      - elasticsearch
    networks:
      - deploy_network
    container_name: indexer

networks:
  deploy_network:
    driver: bridge
Run Code Online (Sandbox Code Playgroud)

indexer.py

from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk

es = Elasticsearch(hosts=[{"host":'elasticsearch'}]) # what should I put here?

actions = [
    {
    '_index' : 'test',
    '_type' : 'content',
    '_id' : str(item['id']),
    '_source' : …
Run Code Online (Sandbox Code Playgroud)

python docker docker-compose elasticsearch-py

4
推荐指数
1
解决办法
3004
查看次数

在本地运行 Azure 机器学习服务管道

我将 Azure 机器学习服务与 azureml-sdk python 库一起使用。

我正在使用 azureml.core 版本 1.0.8

我正在关注这个https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-create-your-first-pipeline教程。

当我使用 Azure 计算资源时,我已经让它工作了。但我想在本地运行它。

我收到以下错误

raise ErrorResponseException(self._deserialize, response)
azureml.pipeline.core._restclients.aeva.models.error_response.ErrorResponseException: (BadRequest) Response status code does not indicate success: 400 (Bad Request).
Trace id: [uuid], message: Can't build command text for [train.py], moduleId [uuid] executionId [id]: Assignment for parameter Target is not specified
Run Code Online (Sandbox Code Playgroud)

我的代码看起来像:

run_config = RunConfiguration()
compute_target = LocalTarget()
run_config.target = LocalTarget()    
run_config.environment.python.conda_dependencies = CondaDependencies(conda_dependencies_file_path='environment.yml')
run_config.environment.python.interpreter_path = 'C:/Projects/aml_test/.conda/envs/aml_test_env/python.exe'
run_config.environment.python.user_managed_dependencies = True
run_config.environment.docker.enabled = False

trainStep = PythonScriptStep(
    script_name="train.py",
    compute_target=compute_target, …
Run Code Online (Sandbox Code Playgroud)

azure-machine-learning-workbench azure-machine-learning-service

4
推荐指数
1
解决办法
1553
查看次数

FastText 0.9.2 - 为什么召回是“nan”?

我使用 Python 接口在 FastText 中训练了一个监督模型,并且在精确度和召回率方面得到了奇怪的结果。

首先,我训练了一个模型:

model = fasttext.train_supervised("train.txt", wordNgrams=3, epoch=100, pretrainedVectors=pretrained_model)
Run Code Online (Sandbox Code Playgroud)

然后我得到测试数据的结果:

def print_results(N, p, r):
    print("N\t" + str(N))
    print("P@{}\t{:.3f}".format(1, p))
    print("R@{}\t{:.3f}".format(1, r))

print_results(*model.test('test.txt'))
Run Code Online (Sandbox Code Playgroud)

但结果总是很奇怪,因为它们显示的精度和召回率 @1 是相同的,即使对于不同的数据集也是如此,例如一个输出是:

N   46425
P@1 0.917
R@1 0.917
Run Code Online (Sandbox Code Playgroud)

然后,当我寻找每个标签的精确度和召回率时,我总是得到“nan”的召回率:

N   46425
P@1 0.917
R@1 0.917
Run Code Online (Sandbox Code Playgroud)

输出是:

{'__label__1': {'precision': 0.9202150724134941, 'recall': nan, 'f1score': 1.8404301448269882}, '__label__5': {'precision': 0.9134956983264135, 'recall': nan, 'f1score': 1.826991396652827}}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么会发生这种情况?

PS:要尝试此行为的可重现示例,请参阅https://github.com/facebookresearch/fastText/issues/1072并使用 FastText 0.9.2 运行它

nlp python-3.x text-classification precision-recall fasttext

4
推荐指数
1
解决办法
1966
查看次数