How to use system_output method in avocado

Best Python code snippet using avocado_python

debug_lp.py

Source:debug_lp.py Github

copy

Full Screen

1"""Evaluate label propagation on a development set.2Usage:3 debug_lp.py --algo=<algo> --sim=<func> --gamma=<val>4Options:5 -h --help Show this screen.6 --algo=<algo> Choose the algorithm (propagate, spread, or nearest) [default: propagate]7 --sim=<func> Choose the similarity function to test (either rbf or expander)8 --gamma=<val> Value of gamma for RBF function9"""10import os11from datetime import datetime 12from collections import defaultdict13from label_propagation import LabelPropagation, expander, RBF, NearestNeighbor,\14 LabelSpreading, NearestNeighborOfAverage15from docopt import docopt16from version import version17def score_lp(system_input, system_output, gold):18 answers = []19 lemma_pos2answers = defaultdict(list)20 for key, input_info in system_input.items():21 assert len(system_output[key]) == len(gold[key]), 'output: %s, gold: %s' % (len(system_output[key]),22 len(gold[key]))23 print('processing', key)24 for index, input_instance in enumerate(input_info):25 #print(index, input_instance)26 if input_instance[0] is None:27 system_answer = system_output[key][index]28 gold_answer = gold[key][index][0]29 #print('system', system_answer, 'gold', gold_answer)30 correct = system_answer == gold_answer31 answers.append(correct)32 lemma_pos2answers[key].append(correct)33 accuracy = sum(answers) / len(answers)34 for lemma_pos, lemma_pos_answers in lemma_pos2answers.items():35 lemma_pos_acc = sum(lemma_pos_answers) / len(lemma_pos_answers)36 print(lemma_pos, len(lemma_pos_answers), lemma_pos_acc)37 print('total', accuracy)38 39if __name__ == '__main__':40 import pickle41 from copy import deepcopy42 arguments = docopt(__doc__)43 print(arguments)44 if arguments['--sim'] == 'expander':45 sim_func = expander46 elif arguments['--sim'] == 'rbf':47 sim_func = RBF(float(arguments['--gamma']))48 else:49 raise ValueError('Unknown similarity function: %s' %arguments['--sim'])50 model_path='/var/scratch/mcpostma/testing/model-google-65/model-google/lstm-wsd-gigaword-google'51 vocab_path='/var/scratch/mcpostma/wsd-dynamic-sense-vector/output/gigaword-lstm-wsd.index.pkl'52# model_path='output/2017-11-24-e93fdb2/lstm-wsd-gigaword-h256p64-seed_12-best-model'53# vocab_path='preprocessed-data/2017-11-24-a74bda6/gigaword-for-lstm-wsd.index.pkl'54 path_system='output/dev.lp'55 path_gold='output/dev.lp.gold'56 path_senses_output = os.path.join('output', version, 'debug_lp__algo-%s_sim-%s_gamma-%s.pkl' 57 %(arguments['--algo'], arguments['--sim'], arguments['--gamma']))58 print('Senses written to %s' %path_senses_output)59 system_input = pickle.load(open(path_system, 'rb'))60 gold = pickle.load(open(path_gold, 'rb'))61 62 old_system_input = deepcopy(system_input)63 assert os.path.exists(vocab_path) and os.path.exists(model_path + '.meta'), \64 'Please update the paths hard-coded in this file (for testing only)'65 import tensorflow as tf66 with tf.Session() as sess:67 if arguments['--algo'] in ('propagate', 'LabelPropagation'): 68 lp = LabelPropagation(sess, vocab_path, model_path, 1000, sim_func=sim_func)69 elif arguments['--algo'] in ('spread', 'LabelSpreading'):70 lp = LabelSpreading(sess, vocab_path, model_path, 1000, sim_func=sim_func)71 elif arguments['--algo'] in ('nearest', 'NearestNeighbor'):72 lp = NearestNeighbor(sess, vocab_path, model_path, 1000, sim_func=sim_func)73 elif arguments['--algo'] in ('average', 'NearestNeighborOfAverage'):74 lp = NearestNeighborOfAverage(sess, vocab_path, model_path, 1000, sim_func=sim_func)75 else:76 raise ValueError('Unknown algorithm: %s' %arguments['--algo'])77 system_output = lp.predict(system_input)78 with open(path_senses_output, 'wb') as outfile:79 pickle.dump(system_output, outfile)80 lp.print_stats()81 print('Finished predicting at %s' %datetime.now())82 # score output (if gold provided)...

Full Screen

Full Screen

telegram_bot.py

Source:telegram_bot.py Github

copy

Full Screen

1import json2from threading import Thread3from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler4# class TelegramBot(Thread):5class TelegramBot():6 def __init__(self, system, json_path):7 # super(TelegramBot, self).__init__()8 self.system = system9 with open(json_path, 'rt') as f:10 setting = json.load(f)11 self.TOKEN = setting["TOKEN"]12 def start(self, update, context):13 input_dir = {'utt':None, 'sessionId':str(update.message.from_user.id)}14 system_output = self.system.initial_message(input_dir)15 update.message.reply_text(system_output['utt'], reply_markup=system_output['markup'])16 def end(self, update, context):17 input_dir = {'utt':None, 'sessionId':str(update.message.from_user.id)}18 system_output = self.system.end_message(input_dir)19 update.message.reply_text(system_output['utt'], reply_markup=system_output['markup'])20 def reset(self, update, context):21 input_dir = {'utt':None, 'sessionId':str(update.message.from_user.id)}22 system_output = self.system.reset_message(input_dir)23 update.message.reply_text(system_output['utt'], reply_markup=system_output['markup'])24 def message(self, update, context):25 input_dir = {'utt':update.message.text, 'sessionId':str(update.message.from_user.id)}26 system_output = self.system.reply(input_dir)27 update.message.reply_text(system_output['utt'], reply_markup=system_output['markup'])28 def button(self, update, context):29 query = update.callback_query30 query.answer()31 reward = query.data32 self.system.button(reward)33 query.edit_message_text(text="{}: {}".format(query.message.text, reward))34 def run(self):35 self.updater = Updater(self.TOKEN, use_context=True)36 print(self.updater.bot.get_me())37 self.updater.dispatcher.add_handler(CommandHandler('start', self.start))38 self.updater.dispatcher.add_handler(CommandHandler('end', self.end))39 self.updater.dispatcher.add_handler(CommandHandler('reset', self.reset))40 self.updater.dispatcher.add_handler(CallbackQueryHandler(self.button))41 self.updater.dispatcher.add_handler(MessageHandler(Filters.text, self.message))42 self.updater.start_polling()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful