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

GraphQL Glance

This is a quick and simple glance to the raw document (in the references), maybe you could treat it as a brief note. Hope it’s helpful to u.

At its core, GraphQL enables declarative data fetching where a client can specify exactly what data it needs from an API. GraphQL is a query language for APIs - not databases.

REST vs GraphQL

  • Data Fetching: multiple endpoints VS single query
  • Over-fetching and Under-fetching (n+1) : fixed data structure VS given exact data
  • Rapid Product Iterations on the Frontend: adjust with data change VS flexible
  • Insightful Analytics on the Backend: fine-grained insights about the data
  • Benefits of a Schema & Type System: type system => schema, frontend and backends can do their work without further communication

More

Bert 论文笔记

Paper: https://arxiv.org/pdf/1810.04805.pdf

Code: https://github.com/google-research/bert

Bert 的核心思想:MaskLM 利用双向语境 + MultiTask。

Abstract

BERT 通过联合训练所有层中的上下文来获取文本的深度双向表示。

Introduction

两种应用 pre-trained model 到下有任务的方法:

  • feature-based:比如 ELMo,将 pre-trained 表示作为额外的特征
  • fine-tuning:比如 OpenAI GPT,引入少量特定任务参数,在下游任务中 fine-tuning 所有的参数

现在的技术有个限制,就是只能采用从左到右的单向机制,这对有些任务是不适合的,比如问答。

Bert 通过 “masked language model” 缓和了这个限制,即随机 mask 输入中的一些 token,目标是只根据上下文(左边和右边)预测 mask 掉的原始 vocabulary id。

同时,还联合训练了一个 “next sentence prediction” 的任务用来表示文本对。

More

Transformer 论文笔记

Paper: https://arxiv.org/pdf/1706.03762.pdf

Code: https://github.com/tensorflow/models/tree/master/official/nlp/transformer

Tool: https://github.com/tensorflow/tensor2tensor

Attention 核心思想:Multi-Head Attention 关注不同位置不同表示子空间的信息,且更容易训练。

Abstract

一个完全基于 Attention 的架构。更容易并行训练,提高训练速度。

Introduction

RNN 的固有属性使其难以并行化(即使通过 factorization tricks 和 conditional computation 可以得到改善),Attention 对依赖关系建模,不考虑输入输出的距离。本文提出的 Transformer 采用了完全的 Attention 机制描述输入和输出的整体依赖关系,在训练速度和效果上都有明显提升。

More