Skip to content

Commit

Permalink
压缩试验只在必要时训练模型
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Feb 1, 2020
1 parent c333dbc commit a0f04a9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/book/ch05/plot_compressed_f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
# 《自然语言处理入门》5.6.3 特征裁剪与模型压缩
# 配套书籍:http://nlp.hankcs.com/book.php
# 讨论答疑:https://bbs.hankcs.com/
import sys
import os

import matplotlib.pyplot as plt
from jpype import JClass

from tests.book.ch03.eval_bigram_cws import CWSEvaluator
from tests.book.ch03.msr import msr_train, msr_model, msr_gold, msr_dict, msr_output, msr_test
from tests.book.ch05.perceptron_cws import CWSTrainer, PerceptronLexicalAnalyzer
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号


def train_evaluate(ratios):
model = CWSTrainer().train(msr_train, msr_train, msr_model, 0, 10, 8).getModel() # 训练模型
# model = JClass('com.hankcs.hanlp.model.perceptron.model.LinearModel')(msr_model)
if not os.path.isfile(msr_model):
model = CWSTrainer().train(msr_train, msr_train, msr_model, 0, 10, 8).getModel() # 训练模型
else:
model = JClass('com.hankcs.hanlp.model.perceptron.model.LinearModel')(msr_model)
pre = -1
scores = []
for c in ratios:
Expand Down

0 comments on commit a0f04a9

Please sign in to comment.