# @aliuq/gpt-3-encoder

> Javascript BPE Encoder Decoder for GPT-2 / GPT-3

Latest version **1.1.5** (published 2023-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @aliuq/gpt-3-encoder
pnpm add @aliuq/gpt-3-encoder
yarn add @aliuq/gpt-3-encoder
bun add @aliuq/gpt-3-encoder
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2023-02-22 |
| First published | 2023-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 5.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | linka |

## Links

- npm: https://www.npmjs.com/package/@aliuq/gpt-3-encoder
- Repository: https://github.com/aliuq/GPT-3-Encoder
- Homepage: https://github.com/aliuq/GPT-3-Encoder#readme
- Issues: https://github.com/aliuq/GPT-3-Encoder/issues
- npm.io page: https://npm.io/package/@aliuq/gpt-3-encoder

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.3.3

## Recent versions

- 1.1.5 (latest) — 2023-02-22
- 1.1.5-beta.2 — 2023-02-22
- 1.1.5-beta.1 — 2023-02-21
- 1.1.5-beta.0 — 2023-02-21

## README

# GPT-3-Encoder

Javascript BPE Encoder Decoder for GPT-2 / GPT-3

Forked from [latitudegames/GPT-3-Encoder](https://github.com/latitudegames/GPT-3-Encoder)

Differences from the original repository:

+ By default, the encoder.json and vocab.bpe files are included in the package, which makes the file size very large.
+ It is possible to provide a CDN file address to load the files.

## Usage

default

```ts
import { decode, encode } from '@aliuq/gpt-3-encoder'

encode(str)
decode(tokens)
```

fetch

encode/decode need an another parameter `options`, which is an object with the following properties:

+ `encoder`: the path of encoder.json file
+ `bpe`: the path of vocab.bpe file

```ts
import { decode, encode } from '@aliuq/gpt-3-encoder/fetch'

const options = {
  encoder: 'https://unpkg.com/@aliuq/gpt-3-encoder/dist/encoder.json',
  bpe: 'https://unpkg.com/@aliuq/gpt-3-encoder/dist/vocab.bpe',
}

encode(str, options)
decode(tokens, options)
```

You need to set `moduleResolution` in `tsconfig.json` to `node16` or `nodenext`, otherwise it will prompt that the type declaration is not found, or you can use `// @ts-expect-error` to ignore the error, If `fetch` and `globalThis.fetch` do not exist, you need to install `axios`.

Also, you can copy the files to your own server and use them.

---
_Source: https://npm.io/package/@aliuq/gpt-3-encoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
