# lingthing

> Character-level ngram-based language modeling

Latest version **0.1.1** (published 2020-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install lingthing
pnpm add lingthing
yarn add lingthing
bun add lingthing
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-01-11 |
| First published | 2020-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Avery Hiebert |
| Maintainers | ahiebert |
| Keywords | nlp, lm, language, model |

## Links

- npm: https://www.npmjs.com/package/lingthing
- Repository: https://github.com/averyhiebert/lingthing
- Homepage: https://github.com/averyhiebert/lingthing#readme
- Issues: https://github.com/averyhiebert/lingthing/issues
- npm.io page: https://npm.io/package/lingthing

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-01-11
- 0.1.0 — 2020-01-11

## README

# ⚡lingthing⚡

A library for n-gram-based character-level language modeling in JavaScript,
intended for use in the browser.

A json file containing counts of n-grams in some training corpus can be
created using the script `scripts/count_grams.py` (or you can use my
example based on the Lancaster-Oslo/Bergen corpus, in 
`scripts/LOB_ngrams.json`).

The resulting json data can then be
used, along with the `lingthing.log_prob` function, to estimate
the (log) probability of a string (with Laplace smoothing applied, and
maybe other smoothing options in the future if we're lucky).

## Installation:

`npm install lingthing`

## Usage Examples:
In Node:
```javascript
const lt = require('lingthing');
const fs = require('fs');

let counts = JSON.parse(fs.readFileSync('scripts/LOB_ngrams.json'));

test_sentence = "Test sentence."
info = lt.corpus_info(counts)
log_probability = lt.log_prob(test_sentence,counts,"laplace",
    info.n,info.d,info.N);

console.log("Probability of sentence '" + test_sentence + "' is " 
    + Math.exp(log_probability));
```

In the browser:
```html
<script src="lingthing-browser-0.0.1.js"></script>
<script src="ngrams.js"></script> <!-- var counts = { 
        ... data generated by scripts/count_grams.py ...};
        ... or you could load the json data by e.g. XMLHttpRequest -->
<script type="text/javascript">
    // Note: importing the browser script is equivalent to:
    // var lingthing = require('lingthing');

    test_sentence = "Test sentence."
    info = lingthing.corpus_info(counts)
    log_probability = lingthing.log_prob(test_sentence,counts,"laplace",
        info.n,info.d,info.N);

    console.log("Probability of sentence '" + test_sentence + "' is " 
        + Math.exp(log_probability));
</script>
```

## Build:
To build the browser-friendly distribution, run `npm install` to
install dev-dependencies, and then run `npm run-script browser`.

The bundled file will appear in the `dist` directory.

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