本文整理汇总了Python中vowpalwabbit.pyvw.vw函数的典型用法代码示例。如果您正苦于以下问题:Python vw函数的具体用法?Python vw怎么用?Python vw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vw函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_keys_with_list_of_values
def test_keys_with_list_of_values():
# No exception in creating and executing model with a key/list pair
model = vw(quiet=True, q=["fa", "fb"])
model.learn('1 | a b c')
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
开发者ID:clxdsjyx,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例2: test_multilabel_prediction_type
def test_multilabel_prediction_type():
model = vw(multilabel_oaa=4, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTILABELS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例3: initialize
def initialize(self, test, resume=False):
if self.model_class == 'lookup':
self.actor_model = {}
elif self.model_class == 'vw_python':
self.actor_model_path = self.base_folder_name + "/model.vw"
if not test:
if not resume:
self.actor_model = pyvw.vw(quiet=True, l2=self.params['l2'], loss_function=self.params['loss_function'], holdout_off=True,
f=self.actor_model_path, b=self.params['b'], lrq=self.params['lrq'], l=self.params['l'], k=True)
else:
self.actor_model = pyvw.vw("--quiet -f {0} -i {0}".format(self.actor_model_path))
else:
self.actor_model = pyvw.vw("--quiet -t -i {0}".format(self.actor_model_path))
开发者ID:joshiatul,项目名称:game_playing,代码行数:16,代码来源:model.py
示例4: test_prob_prediction_type
def test_prob_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='mc', probabilities=True, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pPROB
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例5: test_action_scores_prediction_type
def test_action_scores_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='m', quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTICLASS
prediction = model.predict(' | a b c')
assert isinstance(prediction, int)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例6: test_action_probs_prediction_type
def test_action_probs_prediction_type():
model = vw(cb_explore=2, ngram=2, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pACTION_PROBS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例7: test_scalar_prediction_type
def test_scalar_prediction_type():
model = vw(quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pSCALAR
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:7,代码来源:test_pyvw.py
示例8: test_multiclass_prediction_type
def test_multiclass_prediction_type():
n = 3
model = vw(loss_function='logistic', oaa=n, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTICLASS
prediction = model.predict(' | a b c')
assert isinstance(prediction, int)
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:8,代码来源:test_pyvw.py
示例9: save_and_continue
def save_and_continue(self, thread_id, event):
if self.epochs % 1000.0 == 0 and thread_id == 1:
event.clear()
print "saving model..."
print "epochs: " + str(self.epochs)
self.actor_model.finish()
self.actor_model = pyvw.vw("--quiet --save_resume -f {0} -i {1}".format(self.actor_model_path, self.actor_model_path))
event.set()
开发者ID:joshiatul,项目名称:game_playing,代码行数:8,代码来源:model.py
示例10: test_action_scores_prediction_type
def test_action_scores_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='m', quiet=True)
multi_ex = [model.example('1:1 | a b c'), model.example('2:-1 | a b c')]
model.learn(multi_ex)
assert model.get_prediction_type() == model.pMULTICLASS
multi_ex = [model.example('1 | a b c'), model.example('2 | a b c')]
prediction = model.predict(multi_ex)
assert isinstance(prediction, int)
del model
开发者ID:clxdsjyx,项目名称:vowpal_wabbit,代码行数:9,代码来源:test_pyvw.py
示例11: test_prob_prediction_type
def test_prob_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='mc', probabilities=True, quiet=True)
multi_ex = [model.example('1:0.2 | a b c'), model.example('2:0.8 | a b c')]
model.learn(multi_ex)
assert model.get_prediction_type() == model.pPROB
multi_ex = [model.example('1 | a b c'), model.example('2 | a b c')]
prediction = model.predict(multi_ex)
assert isinstance(prediction, float)
del model
开发者ID:clxdsjyx,项目名称:vowpal_wabbit,代码行数:9,代码来源:test_pyvw.py
示例12: test_scalars_prediction_type
def test_scalars_prediction_type():
n = 3
model = vw(loss_function='logistic', oaa=n, probabilities=True, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pSCALARS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
assert len(prediction) == n
del model
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:9,代码来源:test_pyvw.py
示例13: load
def load(self, verify_on_load=True):
"""
loads model file into memory (as a vw sub-process)
verify model first, then stop process if status is not active
Args:
verify_on_load (bool): flag to call verify when loading a model
"""
self.process = pyvw.vw(self.command)
super(self.__class__, self).load(verify_on_load=verify_on_load)
开发者ID:gramhagen,项目名称:ml-agent,代码行数:12,代码来源:vw_predictor.py
示例14: get_vw
def get_vw(self):
"""Factory to create a vw instance on demand
Returns
-------
pyvw.vw instance
"""
if self.vw_ is None:
self.vw_ = vw(**self.params)
# set label type
self.label_type_ = self.vw_.get_label_type()
return self.vw_
开发者ID:G453,项目名称:vowpal_wabbit,代码行数:13,代码来源:sklearn_vw.py
示例15: test_regressor_args
def test_regressor_args():
# load and parse external data file
data_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources', 'train.dat')
model = vw(oaa=3, data=data_file, passes=30, c=True, k=True)
assert model.predict('| feature1:2.5') == 1
# update model in memory
for _ in range(10):
model.learn('3 | feature1:2.5')
assert model.predict('| feature1:2.5') == 3
# save model
model.save('tmp.model')
del model
# load initial regressor and confirm updated prediction
new_model = vw(i='tmp.model', quiet=True)
assert new_model.predict('| feature1:2.5') == 3
del new_model
# clean up
os.remove('{}.cache'.format(data_file))
os.remove('tmp.model')
开发者ID:Marqt,项目名称:vowpal_wabbit,代码行数:23,代码来源:test_pyvw.py
示例16: mini_vw
def mini_vw(inputFile, numPasses, otherArgs):
vw = pyvw.vw(otherArgs)
for p in range(numPasses):
print 'pass', (p+1)
h = open(inputFile, 'r')
for l in h.readlines():
if learnFromStrings:
vw.learn(l)
else:
ex = vw.example(l)
vw.learn(ex)
ex.finish()
h.close()
vw.finish()
开发者ID:Amano-Ginji,项目名称:vowpal_wabbit,代码行数:15,代码来源:mini_vw.py
示例17: get_vw
vw_args = {
'quiet': True,
'passes': 10,
'cache': True,
'f': "%s-predictor.vw" % topic,
'k': True,
'ngram': 2,
'skips': 2,
'ftrl': True,
'decay_learning_rate': 0.99,
'r': "%s-predictions.txt" % topic,
# 'progressive_validation': "%s-validations.txt" % topic,
'loss_function': 'hinge'
}
vw = pyvw.vw(**vw_args)
for tweet in get_vw('%s-classified.train.vw' % topic):
if (len(tweet) < 3):
continue
if tweet[:1] == '0':
tweet = '-1' + tweet[1:]
ex = vw.example(tweet)
vw.learn(ex)
# print(vw.predict(ex))
# print(ex)
print("%s" % (re.sub(r'\n', '', tweet)))
# out.write(features + "\n")
# counter += 1
开发者ID:malberich,项目名称:pgds-etl-filters,代码行数:31,代码来源:active-learner-json.py
示例18: my_predict
from vowpalwabbit import pyvw
def my_predict(vw, ex):
pp = 0.
for f,v in ex.iter_features():
pp += vw.get_weight(f) * v
return pp
def ensure_close(a,b,eps=1e-6):
if abs(a-b) > eps:
raise Exception("test failed: expected " + str(a) + " and " + str(b) + " to be " + str(eps) + "-close, but they differ by " + str(abs(a-b)))
###############################################################################
vw = pyvw.vw("--quiet")
###############################################################################
vw.learn("1 |x a b")
###############################################################################
print('# do some stuff with a read example:')
ex = vw.example("1 |x a b |y c")
ex.learn() ; ex.learn() ; ex.learn() ; ex.learn()
updated_pred = ex.get_updated_prediction()
print('current partial prediction =', updated_pred)
# compute our own prediction
开发者ID:JohnLangford,项目名称:vowpal_wabbit,代码行数:30,代码来源:test.py
示例19: range
sortedSpans = []
for s in spans: sortedSpans.append(s)
sortedSpans.sort()
oracle = []
for id in range(len(sortedSpans)):
if sortedSpans[id][0] > sortedSpans[0][0]: break
oracle.append( sortedSpans[id][1] )
pred = self.sch.predict(examples = examples,
my_tag = i+1,
oracle = oracle,
condition = [ (i, 'p'), (i-1, 'q') ] )
self.vw.finish_example(examples)
output.append( spans[pred][2] )
for j in spans[pred][2]:
covered[j] = True
return output
print('training LDF')
vw = pyvw.vw("--search 0 --csoaa_ldf m --search_task hook --ring_size 1024 --quiet -q ef -q ep")
task = vw.init_search_task(WordAligner)
for p in range(10):
task.learn(my_dataset)
print('====== test ======')
print(task.predict( ("the blue flower".split(), ([],[],[]), "la fleur bleue".split()) ))
print('should have printed [[0], [2], [1]]')
开发者ID:JohnLangford,项目名称:vowpal_wabbit,代码行数:30,代码来源:word_alignment.py
示例20: print
ds = config['DecisionService']
cache_folder = ds['CacheFolder']
for root, subdirs, files in os.walk(os.path.join(cache_folder, 'onlinetrainer')):
print('looking at folder {0}'.format(root))
model = None
trackback = None
for file in files:
if file == 'model':
model = os.path.join(root, file)
continue
if file == 'model.trackback':
trackback = os.path.join(root, file)
continue
if model is None or trackback is None:
continue
print('looking at folder {0}'.format(root))
with open(trackback, 'r') as f:
first_line = f.readline()
if (first_line.startswith('modelid:')):
continue
vw = pyvw.vw("--quiet -i {0}".format(model))
id = vw.get_id()
del vw
line_prepender(trackback, 'modelid: {0}\n'.format(id))
开发者ID:GalOshri,项目名称:mwt-ds,代码行数:30,代码来源:InsertModelIdIntoTrackback.py
注:本文中的vowpalwabbit.pyvw.vw函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论