The Rust Programming Language Brief Note (Vol4-Advance)

15 Smart Pointers

Reference counting smart pointer enables you to have multiple owners of data by keeping track of the number of owners and, when no owners remain, cleaning up the data.

References are pointers that only borrow data; in contrast, in many cases, smart pointers own the data they point to.

Smart pointers are usually implemented using structs. The characteristic that distinguishes a smart pointer from an ordinary struct is that smart pointers implement the Deref and Drop traits.

  • The Deref trait allows an instance of the smart pointer struct to behave like a reference so you can write code that works with either references or smart pointers.
  • The Drop trait allows you to customize the code that is run when an instance of the smart pointer goes out of scope.

More

自然语言记忆模块(NLM)

本文主要介绍自然语言的记忆(存储与查询)模块,初衷是作为 chatbot 的 Layer 之一,主要功能是记忆(存储)从对话或训练数据学到的 “知识”,然后在需要时唤起(查询) 。目前成熟的方法是以图数据库作为载体,将知识存储为一系列的 ”节点“ 和 ”关系“。之后再基于这些存储的 ”节点“ 和 ”关系“ 进行相关查询。也可以理解为构建 Data Model 的问题。

项目地址:https://github.com/hscspring/NLM

设计思想

图数据库的典型代表是 Neo4j,Neo4j 中有几个很重要的概念:标签、节点和关系。标签是一类节点,可以看作是节点的类别,节点一般是某一个实体;关系存在于两个实体间,可以有多种不同的关系。节点和关系可以有多个属性。实践来看,Python 语言可以使用社区的 technige/py2neo,当然还可以使用官方的 neo4j/neo4j-python-driver: Neo4j Bolt driver for Python,两者的目的都是将数据 import 进 database 并进行相应的查询。

Neo4j 的特点要求导入的数据尽量是结构化的,也就是我们要事先有实体和它的类别(实体的属性可有可无),实体与实体间的关系(关系的属性可有可无)。我们期待能从对话或无监督的语料中自动提取实体和关系,然后自动 import 进 Neo4j。为了避免导入数据的混乱,自然最好能有先验的 “类别”,比如节点类别 Person,Movie 等,关系类别 LOVES,ACTS 等。所以,对于文本输入,我们需要一个信息提取器,将文本中的符合先验类别的节点和关系提取出来。如果输入是 NLU 模块输出的 ”意图和实体“ ,则需要一个分类器,将意图分类到对应的 Relation 类别,将实体分类到 Node 类别。

More

Python 小白快速从入门到放弃:使用框架

随着学习的不断深入,我们肯定会越来越不满足只在 Jupyter Notebook 中写一些小任务。我们可能会希望做一个 Web 应用,或者一个小程序,甚至是一个 APP。对于这种系统性的工程项目,框架就必不可少了,它可以极大地提高我们的效率。这节课我们就以 Python 的 Django 框架为例来开发一个小的 Web 应用程序。

More

Python 小白快速从入门到放弃:在结束后

这个系列的课程的目标在《在开始前》已经说得很清楚了:解决重复劳动或自己做好玩儿的小项目;尝试新的思维方式。这短短的几节课要想把 Python 的相关知识面面俱到是不可能的,但我觉得已经给出了一个全图景,大家只要围绕这个做,达到目标应该是不成问题的。我想说的还是一直提倡的:Just do it,在实践中不断成长。

More

Python 小白快速从入门到放弃:使用模块

上节介绍了函数,简单理解就是实现特定功能的一组代码,方便复用。本节介绍的模块其实就是把函数组合起来作为模块,让更加便利地完成任务。使用模块我们可以非常迅速地实现很多任务,而不用自己动手实现。Python 中的模块分为内置的(Python 安装后就有的)和社区模块(需要通过 pip install xxx 安装的)。

More

CTRL 论文+代码+实践笔记

paper: [1909.05858] CTRL: A Conditional Transformer Language Model for Controllable Generation

code: salesforce/ctrl: Conditional Transformer Language Model for Controllable Generation

核心思想:借鉴多任务,将文本标签作为输入的一部分(放在开头)控制文本生成。

Abstract

文本生成最大的问题是难以对其进行控制,本文发布了一个 1.6 billion 参数的条件 transformer language model,训练能够 govern 风格、内容、特定任务行为等的控制代码。控制代码来自与原始文本共现的结构,保留了无监督学习的优点,同时提供对文本生成更明确的控制。这些控制代码还允许 CTRL 预测训练数据的哪些部分最有可能给出序列。

More

GraphQL Elixir Glance

There are several problems with the origin docs, so I reproduced this quick glance. It’s much simple and only contains the brief information. Hope this is helpful to u.

Getting Started

Schema-Driven Development

  • Define your types and the appropriate queries and mutations for them.
  • Implement functions called resolvers to handle these types and their fields.
  • As new requirements arrive, go back to step 1 to update the schema, and continue through the other steps.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Step1: create
$ mix phx.new community --no-html

# Step2: add dependencies to `mix.exs`
{:dataloader, "~> 1.0.0"}, # absinthe_ecto was DEPRECATED
{:absinthe_plug, "~> 1.4.0"}

# Step3: modify database info in `config/dev.exs`
# maybe you should modify username or password

# Step4: install deps
$ mix deps.get

# Step5: generate tables and seed data
$ mix phx.gen.context News Link links url:string description:text

# Step6: add seed data in `priv/repo/seeds.exs`
alias Community.News.Link
alias Community.Repo
%Link{url: "http://graphql.org/", description: "The Best Query Language"} |> Repo.insert!
%Link{url: "http://dev.apollodata.com/", description: "Awesome GraphQL Client"} |> Repo.insert!

# Step7: setup ecto (create + migrate)
$ mix ecto.setup

You should see two pieces of items in the links table.

More