MCPcopy Create free account
hub / github.com/2shou/TextGrocery

github.com/2shou/TextGrocery @0.1.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.3 ↗ · + Follow
232 symbols 528 edges 28 files 25 documented · 11% updated 5y ago0.1.3 · 2015-02-12★ 68312 open issues

Browse by type

Functions 188 Types & classes 44
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TextGrocery

Build Status

A simple, efficient short-text classification tool based on LibLinear

Embed with jieba as default tokenizer to support Chinese tokenize

Other languages: 更详细的中文文档

Performance

  • Train set: 48k news titles with 32 labels
  • Test set: 16k news titles with 32 labels
  • Compare with svm and naive-bayes of scikit-learn
Classifier Accuracy Time cost(s)
scikit-learn(nb) 76.8% 134
scikit-learn(svm) 76.9% 121
TextGrocery 79.6% 49

Sample Code

>>> from tgrocery import Grocery
# Create a grocery(don't forget to set a name)
>>> grocery = Grocery('sample')
# Train from list
>>> train_src = [
    ('education', 'Student debt to cost Britain billions within decades'),
    ('education', 'Chinese education for TV experiment'),
    ('sports', 'Middle East and Asia boost investment in top level sports'),
    ('sports', 'Summit Series look launches HBO Canada sports doc series: Mudhar')
]
>>> grocery.train(train_src)
# Or train from file
>>> grocery.train('train_ch.txt')
# Save model
>>> grocery.save()
# Load model(the same name as previous)
>>> new_grocery = Grocery('sample')
>>> new_grocery.load()
# Predict
>>> new_grocery.predict('Abbott government spends $8 million on higher education media blitz')
education
# Test from list
>>> test_src = [
    ('education', 'Abbott government spends $8 million on higher education media blitz'),
    ('sports', 'Middle East and Asia boost investment in top level sports'),
]
>>> new_grocery.test(test_src)
# Return Accuracy
1.0
# Or test from file
>>> new_grocery.test('test_ch.txt')
# Custom tokenize
>>> custom_grocery = Grocery('custom', custom_tokenize=list)

More examples: sample/

Install

$ pip install tgrocery

Only test under Unix-based System

Core symbols most depended-on inside this repo

Shape

Method 106
Function 82
Class 44

Languages

Python53%
C++33%
C14%

Modules by API surface

tgrocery/learner/liblinear/linear.cpp56 symbols
tgrocery/learner/learner.py29 symbols
tgrocery/converter.py28 symbols
tgrocery/learner/liblinear/python/liblinear.py22 symbols
tgrocery/learner/liblinear/train.c12 symbols
tgrocery/__init__.py12 symbols
tgrocery/base.py11 symbols
tgrocery/learner/liblinear/tron.cpp10 symbols
tgrocery/classifier.py10 symbols
tgrocery/learner/util.c8 symbols
tgrocery/learner/liblinear/predict.c8 symbols
tgrocery/learner/liblinear/python/liblinearutil.py7 symbols

For agents

$ claude mcp add TextGrocery \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page