Views
No views yet
import fasttext, os
if not os.path.exists("expert_classify.ftz"):
os.system("wget http://dl.turkunlp.org/register-labeling-model/fasttext_model.bin")
os.system("wget https://huggingface.co/ontocord/riverbed/resolve/main/rj_model.bin")
os.system("wget https://huggingface.co/kenhktsui/llm-data-textbook-quality-fasttext-classifer-v1/resolve/main/model_textbook_quality.bin")
os.system("wget https://huggingface.co/ontocord/riverbed/resolve/main/expert_classify.ftz")
### red pajama filter. pred_label "__label__wiki" is data we do not wish to keep.
red_pajama_model = fasttext.load_model("rj_model.bin")
(pred_label, pred_prob) = red_pajama_model.predict(text)
if pred_label == "__label__cc":
pred_prob = 1 - pred_prob
### turkunlp registry labeler: https://github.com/TurkuNLP/register-labeling
domain_model = fasttext.load_model("fasttext_model.bin")
(pred_label, pred_prob) = domain_model.predict(text)
### Pile domain such as github, arxiv, etc.
pile_model = fasttext.load_model("expert_classify.ftz")
(pred_label, pred_prob) = pile_model.predict(text)
### Textbook quality - e.g., textbooks are all you need
textbook_model = fasttext.load_model("model_textbook_quality.bin")
(pred_label, pred_prob) = pile_model.predict(text)
1
2if not os.path.exists("./wikidata_bm25_whoosh"):
3 os.system("git clone https://huggingface.co/ontocord/riverbed")
4 os.system("pip install -q whoosh")
5import whoosh.index as whoosh_index
6from whoosh.qparser import QueryParser
7from whoosh.analysis import StemmingAnalyzer, Filter
8class MyFilter(Filter):
9 def __call__(self, tokens):
10
11 for t in tokens:
12 t.text = t.text.lower()
13 if len(t.text) > 5:
14 yield t
15 t.text = t.text[:5]
16 yield t
17
18try:
19 if qp is None: assert False
20except:
21 bm25_dir = "./riverbed"
22 index = whoosh_index.open_dir(bm25_dir)
23 searcher = index.searcher()
24 qp = QueryParser("content", schema=index.schema)