自然语言处理学习日记16

编程入门 行业动态 更新时间:2024-10-26 20:24:24

<a href=https://www.elefans.com/category/jswz/34/1768401.html style=自然语言处理学习日记16"/>

自然语言处理学习日记16

1.Rasa从服务器获取模型
解析:可以配置HTTP服务器以从其它URL获取模型:

asa run --enable-api --log-file out.log --endpoints my_endpoints.yml

模型服务器在端点配置[my_endpoints.yml]中指定,可以在其中指定服务器URL Rasa定期查询压缩的Rasa模型:

  url: @latestwait_time_between_pulls: 10   # [optional](default: 100)

2.从远程存储中获取模型
解析:可以配置Rasa服务器以从远程存储中获取模型:

rasa run -m 20190506-100418.tar.gz --enable-api --log-file out.log --remote-storage aws

该模型将下载并存储在本地存储系统的临时目录中。

3.Rasa内置身份验证方法
解析:
[1]基于令牌的身份验证
启动服务器时使用–auth-token thisismysecret传递令牌:

rasa run \
-m models \
--enable-api \
--log-file out.log \
--auth-token thisismysecret

请求应该传递令牌,在案例中是thisismysecret作为参数:

curl -XGET localhost:5005/conversations/default/tracker?token=thisismysecret

[2]基于JWT的Auth
使用–jwt-secret thisismysecret启用基于JWT的身份验证:

rasa run \
-m models \
--enable-api \
--log-file out.log \
--jwt-secret thisismysecret

请求应该设置正确的JWT标头:

"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ""zdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIi""wiaWF0IjoxNTE2MjM5MDIyfQ.qdrr2_a7Sd80gmCWjnDomO""Gl8eZFVfKXA6jhncgRn-I"

4.配置SSL/HTTPS
解析:

rasa run --ssl-certificate myssl.crt --ssl-keyfile myssl.key
rasa run --ssl-certificate myssl.crt --ssl-keyfile myssl.key --ssl-password mypassword

5.Endpoint配置
解析:要将Rasa连接到其它端点,可以在YAML文件中指定端点配置。然后使用标志–endpoints

--m <Rasa model> \
--endpoints <path to endpoint configuration>.yml

可以使用${name of environment variable}指定配置文件中的环境变量。然后这些占位符将替换为环境变量的值。

6.Websocket Channel
解析:需要在credentials.yml文件中配置如下内容:

socketio:user_message_evt: user_utteredbot_message_evt: bot_utteredsession_persistence: true/false

7.REST Channels
解析:
[1]RestInput
需要在credentials.yml文件中配置如下内容:

rest:# you don't need to provide anything here - this channel doesn't# require any credentials

[2]CallbackInput
需要在credentials.yml文件中配置如下内容:

callback:# URL to which Core will send the bot responsesurl: "http://localhost:5034/bot"

8.WebSocket
解析:在WebSocket API中,浏览器和服务器只需要做一个握手的动作,然后,浏览器和服务器之间就形成了一条快速通道。两者之间就直接可以数据互相传送。

9.CURL发送POST请求
解析:
[1]-H:请求头。
[2]-d:POST内容。
[3]-X:请求协议。

10.Rasa启动REST服务
解析:rasa run -m models --enable-api --cors “*” --debug

11.jwt原理
解析:jwt的原理就是服务端根据secret生成token。如下所示:

import jwt 
payload = {"user": {"username": "user123", "role": "admin"}}
signed = jwt.encode(payload, "secret", algorithm='HS256')
header = {"Authorization": "Bearer {}".format(signed)}

说明:-H 'Authorization: Bearer <signed>'。

12.class rasa.core.trackers.DialogueStateTracker(sender_id, slots, max_event_history=None)
解析:
[1]current_slot_values():Return the currently set values of the slots.
[2]get_slot(key):Retrieves the value of a slot.

13.sklearn.feature_extraction.text.CountVectorizer
解析:
[1]1-gram例子

from sklearn.feature_extraction.text import CountVectorizer
corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?',]
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(corpus)
print(vectorizer.get_feature_names())
print(X.toarray())

输出结果,如下所示:

['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third', 'this']
[[0 1 1 1 0 0 1 0 1][0 2 0 1 0 1 1 0 1][1 0 0 1 1 0 1 1 1][0 1 1 1 0 0 1 0 1]]

[2]2-gram例子

from sklearn.feature_extraction.text import CountVectorizer
corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?',]
vectorizer2 = CountVectorizer(analyzer='word', ngram_range=(2, 2))
X2 = vectorizer2.fit_transform(corpus)
print(vectorizer2.get_feature_names())
print(X2.toarray())

输出结果,如下所示:

['and this', 'document is', 'first document', 'is the', 'is this', 'second document', 'the first', 'the second', 'the third', 'third one', 'this document', 'this is', 'this the']
[[0 0 1 1 0 0 1 0 0 0 0 1 0][0 1 0 1 0 1 0 1 0 0 1 0 0][1 0 0 1 0 0 0 0 1 1 0 1 0][0 0 1 0 1 0 1 0 0 0 0 0 1]]

14.token_pattern: (?u)\b\w+\b
解析:
[1](?u):表示匹配中对大小写不敏感。
[2]中间的\b和末尾的\b:表示匹配两个词语的间隔。
[3]\w+:表示匹配一个或者多个字母或数字或下划线或汉字。
说明:默认会过滤掉只有一个字符长度的词,比如I,a,我,爱等。

15.实体链接
解析:实体链接是指将文本中的实体指称链向知识库实体的过程,它能够丰富文本语义信息,在自然语言处理、信息检索等领域有着广泛的应用前景。

16.TypeError: _run_request_middleware() got an unexpected keyword argument 'request_name’
解析:pip install sanic==19.9.0

17.

参考文献:
[1]Your Own Website:/
[2]botfront/rasa-webchat:
[3]HTML5 WebSocket:.html
[4]scalableminds/chatroom:
[5]Custom Connectors:/
[6]Text feature extraction:.html#text-feature-extraction
[7]Understanding Rasa Tensorflow intent classifier:/@tatiana.parshina/understanding-rasa-tensorflow-intent-classifier-e9d4ef019c6
[8]How to take the full control of Rasa Embedding Classifier:/?p=326
[9]
[10]

更多推荐

自然语言处理学习日记16

本文发布于:2024-03-12 15:29:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1731823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自然语言   日记

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!