npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gibun

v0.3.1

Published

日本語用、テスト文章生成ライブラリ。マルコフ連鎖を使用しています

Readme

Gibun

Gibunは、日本語のフェイク文章を生成するライブラリです。

形態素解析とマルコフ連鎖を使用し、ある程度自然な文章を生成します。

GPTなどの生成AIを使用するほどでもない、テストデータ生成などでご使用ください。

デモ

下記でデモを確認できます。ブラウザのみで動いています。

https://mohhh-ok.github.io/gibun/

インストール

npm i -D gibun

デフォルトでは軽量なtiny-segmenterを使用します。より高精度な形態素解析が必要な場合は、kuromojinを追加でインストールしてください。

npm i -D gibun kuromojin

使い方

基本的な使い方

デフォルトではtiny-segmenterによる形態素解析を使用します。

import { Gibun } from 'gibun';

const gibun = new Gibun();

// プリセットを読み込む
await gibun.trainPreset('business');

// 文章を生成
const result = gibun.generate({ minLength: 30, maxLength: 50 });
console.log(result);

カスタムTokenizerを使用する

より高精度な形態素解析が必要な場合は、createKuromojinTokenizerを使用できます。

import { Gibun, createKuromojinTokenizer } from 'gibun';

// kuromojinを使用するインスタンスを作成
const gibun = new Gibun({
  tokenizer: createKuromojinTokenizer()
});

await gibun.trainPreset('business');
const result = gibun.generate({ minLength: 30, maxLength: 50 });
console.log(result);

独自のTokenizerを実装することもできます。

import { Gibun, Token } from 'gibun';

// カスタムTokenizerを作成
const customTokenizer = async (text: string): Promise<Token[]> => {
  // 独自の形態素解析処理
  const tokens = yourCustomAnalyzer(text);
  return tokens.map(token => ({
    value: token.surface,
    isNoun: token.partOfSpeech === '名詞'
  }));
};

const gibun = new Gibun({
  tokenizer: customTokenizer
});

独自文章を使用する

独自文章をトレーニングすることも可能です。

import { Gibun } from 'gibun';

const gibun = new Gibun();

await gibun.train(`
  私はその人を常に先生と呼んでいた。だからここでもただ先生と書くだけで本名は打ち明けない。
  これは世間をはばかる遠慮というよりも、そのほうが私にとって自然だからである。
  私はその人の記憶を呼び起こすごとに、すぐ「先生」と言いたくなる。
  筆を執っても心持ちは同じことである。
  よそよそしい頭かしら文も字じなどはとても使う気にならない。
`);

const result = gibun.generate({ minLength: 20, maxLength: 30 });
console.log(result); // 自然だからである。これは同じことである。私は同じことで本名は

プリセット一覧

以下のプリセットをサンプルとして同梱しています。

現代風ジャンル別

  • business - ビジネス文書風(議事録、報告書など)
  • sns - SNS投稿風(カジュアルな短文、絵文字入り)
  • blog - ブログ記事風(です・ます調の説明文)
  • news - ニュース記事風(客観的な報道文)

プロフィール系

  • profile_business - ビジネス向けプロフィール文
  • profile_sns - SNS向けプロフィール文

文学作品

  • cat - 吾輩は猫である(夏目漱石)

API

プリセットでトレーニング

事前に用意されたプリセットを使用してトレーニングします。

gibun.trainPreset(preset: PresetName): Promise<void>

パラメータ:

  • preset: プリセット名(文字列)

例:

await gibun.trainPreset('business');
await gibun.trainPreset('sns');
await gibun.trainPreset('cat');

トレーニング

文章を渡します。

gibun.train(text: string | string[], options?: { split?: boolean }): Promise<void>

パラメータ:

  • text: トレーニング用の文章(文字列または文字列配列)
  • options.split: true の場合、句点で文章を自動分割します(デフォルト: false

例:

await gibun.train('吾輩は猫である。');
await gibun.train(['名前はまだ無い。', 'どこで生れたかとんと見当がつかぬ。']);
await gibun.train('吾輩は猫である。名前はまだ無い。', { split: true });

生成

文章を生成します。

gibun.generate(params?: { minLength: number, maxLength?: number }): string

パラメータ:

  • minLength: 最小文字数(デフォルト: 100)
  • maxLength: 最大文字数(省略可)

例:

gibun.generate({ minLength: 20, maxLength: 30 });
gibun.generate({ minLength: 50 }); // maxLengthなし

Tokenizerについて

デフォルトTokenizer(TinySegmenter)

デフォルトではtiny-segmenterを使用します。

メリット:

  • 軽量で高速
  • Node.js・ブラウザ両対応
  • 辞書不要

デメリット:

  • 名詞の抽出ができないため、生成文章の冒頭が不自然になる可能性がある

KuromojinTokenizer

より高精度な形態素解析にはkuromojinを使用できます。

メリット:

  • 名詞の抽出により生成文章の冒頭が安定する
  • 高精度な形態素解析

デメリット:

  • Node.jsのみ対応(ブラウザ未対応)
  • 辞書ファイルの読み込みが必要

カスタムTokenizer

独自の形態素解析エンジン(MeCab、Sudachiなど)を使用することも可能です。Tokenizer型に準拠した関数を実装してください。

type Token = {
  value: string;    // トークンの文字列
  isNoun: boolean;  // 名詞かどうか
};

type Tokenizer = (text: string) => Promise<Token[]>;

複数インスタンスの管理

異なるトレーニングデータやTokenizerを分離して管理できます。

import { Gibun, createKuromojinTokenizer } from 'gibun';

// ビジネス用(高精度)
const businessGibun = new Gibun({
  tokenizer: createKuromojinTokenizer()
});
await businessGibun.trainPreset('business');
const businessText = businessGibun.generate({ minLength: 30, maxLength: 50 });

// SNS用(軽量)
const snsGibun = new Gibun(); // デフォルトのtiny-segmenterを使用
await snsGibun.trainPreset('sns');
const snsText = snsGibun.generate({ minLength: 20, maxLength: 40 });

ライセンス

MIT