예제 #1
0
def test_reverse_words():
    old_limit = config.recursion_limit
    config.recursion_limit = 100000
    with tempfile.NamedTemporaryFile() as f_save,\
            tempfile.NamedTemporaryFile() as f_data:
        with open(f_data.name, 'wt') as data:
            for i in range(10):
                print("A line.", file=data)
        main("train", f_save.name, 1, [f_data.name])
    config.recursion_limit = old_limit
def test_reverse_words():
    old_limit = config.recursion_limit
    config.recursion_limit = 100000
    with tempfile.NamedTemporaryFile() as f_save,\
            tempfile.NamedTemporaryFile() as f_data:
        with open(f_data.name, 'wt') as data:
            for i in range(10):
                print("A line.", file=data)
        main("train", f_save.name, 1, [f_data.name])

        real_stdin = sys.stdin
        sys.stdin = StringIO('abc\n10\n')
        main("beam_search", f_save.name, 10)
        sys.stdin = real_stdin


    config.recursion_limit = old_limit
예제 #3
0
"""
import logging
import argparse
from reverse_words import main

if __name__ == "__main__":
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s: %(levelname)s: %(message)s")
    parser = argparse.ArgumentParser(
        "Case study of learning to reverse words in a text.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "mode",
        choices=["train", "sample", "beam_search"],
        help="The mode to run. In the `train` mode a model is trained."
        " In the `sample` and `beam_search` modes a trained model is "
        " to used reverse words in the input text.")
    parser.add_argument(
        "save_path",
        default="chain",
        help="The path to save the training process if the mode"
        " is `train` OR path to an `.npz` files with learned"
        " parameters if the mode is `test`.")
    parser.add_argument("--num-batches",
                        default=10000,
                        type=int,
                        help="Train on this many batches.")
    args = parser.parse_args()
    main(**vars(args))
예제 #4
0
from reverse_words import main

if __name__ == "__main__":
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s: %(levelname)s: %(message)s")
    parser = argparse.ArgumentParser(
        "Case study of learning to reverse words in a text.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "mode", choices=["train", "sample", "beam_search"],
        help="The mode to run. In the `train` mode a model is trained."
             " In the `sample` and `beam_search` modes a trained model is "
             " to used reverse words in the input text.")
    parser.add_argument(
        "save_path", default="reverse_words.tar", nargs='?',
        help="The path to save the training process if the mode"
             " is `train` OR path to an `.tar` files with learned"
             " parameters if the mode is `test`.")
    parser.add_argument(
        "--num-batches", default=10000, type=int,
        help="Train on this many batches.")
    parser.add_argument(
        "--data-path",
        help="text file(s) to read for training, with bash-like expansion"
             " so wildchars can be used (e.g. data/*.txt)")
    args = parser.parse_args()
    if args.data_path:
        args.data_path = glob.glob(args.data_path)
    main(**vars(args))