previd = c.get_track(prev).id curid = c.get_track(cur).id print "%s -> %s" % (previd, curid) print "---" scores = c.get_transitions_from_id(previd) print_histogram(c, scores) if playcount > 0: playcount -= 1 else: cmd = read_chr().lower() if cmd == "g": c.record_user_feedback(True) elif cmd == "b": c.record_user_feedback(False) elif cmd == "p": playcount = 10 elif cmd == "q": sys.exit() # If the last choice wasn't bad, continue to the next track if not cmd == "b": prev = cur cur = c.choose_next_track(prev) c.unload() if __name__ == "__main__": run_demo(main)
parser.add_argument('--seed', type=int, default=5431916812, help='random seed') parser.add_argument('--log-interval', type=int, default=10, metavar='N', help='report interval') parser.add_argument('--checkpoint', type=str, default='None', help='path to load the checkpoint') parser.add_argument('--save', type=str, default='mlm_bert.pt', help='path to save the final model') parser.add_argument('--save-vocab', type=str, default='torchtext_bert_vocab.pt', help='path to save the vocab') parser.add_argument('--mask_frac', type=float, default=0.15, help='the fraction of masked tokens') parser.add_argument('--dataset', type=str, default='WikiText2', help='dataset used for MLM task') parser.add_argument('--parallel', type=str, default='None', help='Use DataParallel to train model') parser.add_argument('--world_size', type=int, default=8, help='the world size to initiate DPP') parser.add_argument('--gradient-accumulation', dest='gradient_accumulation', default=False, action='store_true', help='Enable gradient accumulation') args = parser.parse_args() if args.parallel == 'DDP': run_demo(run_ddp, run_main, args) else: run_main(args, adaptdl.env.replica_rank()) time.sleep(100)
import sys sys.path.append(".") import random from conductor.engine.markov import MarkovConductor from utils import run_demo def main(args): c = MarkovConductor("/tmp/conductor-test.db") c.load() tracks = [{"title": "Blue", "album": "Cold", "artist": "Colors", "genre": "Electronic"}, {"title": "Cyan", "album": "Cold", "artist": "Colors", "genre": "Electronic"}, {"title": "Green", "album": "Cold", "artist": "Colors", "genre": "Electronic"}, {"title": "Purple", "album": "Cold", "artist": "Colors", "genre": "Electronic"}, {"title": "One", "album": "Low", "artist": "Numbers", "genre": "Math Rock"}] prev = None for i in range(0, 200): cur = random.choice(tracks) print cur, prev c.record_transition(prev, cur) prev = cur c.unload() if __name__ == "__main__": run_demo(main)
# Manually choose next tracks. for track in self.prompt_tracks(): self.play_track(track, userchoice=True) continue elif cmd == "x": # Forget about the previous track to simulate a session beginning. self.previous_track = None print "New session started." continue elif cmd == "q": # "Quit" print "Bye!" sys.exit() curid = self.conductor.get_track(self.current_track).id if self.current_track else None scores = self.conductor.get_transitions_from_id(curid) print "---" print "%s -> ..." % (self.current_track["title"] if self.current_track else "[Start]") print_histogram(self.conductor, scores) print "---" self.play_track(self.conductor.choose_next_track(self.current_track), userchoice=False) self.conductor.unload() if __name__ == "__main__": player = SimpleConsolePlayer() run_demo(player.run)
help='path to load the checkpoint') parser.add_argument('--save', type=str, default='ns_model.pt', help='path to save the final model') parser.add_argument('--save-vocab', type=str, default='vocab.pt', help='path to save the vocab') parser.add_argument('--bert-model', type=str, help='path to save the pretrained bert') parser.add_argument('--frac_ns', type=float, default=0.5, help='fraction of not next sentence') parser.add_argument('--parallel', type=str, default='None', help='Use DataParallel/DDP to train model') parser.add_argument('--world_size', type=int, default=1, help='the world size to initiate DPP') args = parser.parse_args() if args.parallel == 'DDP': run_demo(run_ddp, args) else: run_main(args)
elif cmd == "x": # Forget about the previous track to simulate a session beginning. self.previous_track = None print "New session started." continue elif cmd == "q": # "Quit" print "Bye!" sys.exit() curid = self.conductor.get_track( self.current_track).id if self.current_track else None scores = self.conductor.get_transitions_from_id(curid) print "---" print "%s -> ..." % (self.current_track["title"] if self.current_track else "[Start]") print_histogram(self.conductor, scores) print "---" self.play_track(self.conductor.choose_next_track( self.current_track), userchoice=False) self.conductor.unload() if __name__ == "__main__": player = SimpleConsolePlayer() run_demo(player.run)