How to use the parlai.core.teachers.FbDialogTeacher function in parlai

To help you get started, we’ve selected a few parlai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookresearch / ParlAI / parlai / tasks / mctest / agents.py View on Github external
from parlai.core.teachers import FbDialogTeacher
from .build import build

import copy
import os


def _path(opt, filtered):
    # Build the data if it doesn't exist.
    build(opt)
    dt = opt['datatype'].split(':')[0]
    return os.path.join(opt['datapath'], 'MCTest', dt + filtered + '.txt')


class Task160Teacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt, '160')
        super().__init__(opt, shared)


class Task500Teacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt, '500')
        super().__init__(opt, shared)


class DefaultTeacher(Task500Teacher):
    pass
github facebookresearch / ParlAI / parlai / tasks / dbll_movie / agents.py View on Github external
# Each individual task.
class TaskTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        params = opt['task'].split(':')[2]
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(os.path.join('movieqa-dbll', 'movieqa1'), params, opt)
        opt['cands_datafile'] = os.path.join(
            opt['datapath'], 'WikiMovies', 'movieqa', 'knowledge_source', 'entities.txt'
        )
        super().__init__(opt, shared)


# Defaults to task 2 with p=0.5.
class DefaultTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        task = "2_p0.5"
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(os.path.join('movieqa-dbll', 'movieqa1'), task, opt)
        opt['cands_datafile'] = os.path.join(
            opt['datapath'], 'WikiMovies', 'movieqa', 'knowledge_source', 'entities.txt'
        )
        super().__init__(opt, shared)
        self.defaultPosReward = 1
github facebookresearch / ParlAI / parlai / tasks / wmt / agents.py View on Github external
from parlai.core.teachers import FbDialogTeacher
from .build import build

import copy
import os


def _path(task, opt, dt):
    # Build the data if it doesn't exist.
    build(opt)
    return os.path.join(
        opt['datapath'], 'wmt', '{task}_{type}.txt'.format(task=task, type=dt)
    )


class EnDeTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        self.task_name = 'en_de'
        dt = opt['datatype'].split(':')[0]
        opt['datafile'] = _path(self.task_name, opt, dt)
        super().__init__(opt, shared)


class DefaultTeacher(EnDeTeacher):
    pass
github facebookresearch / ParlAI / parlai / tasks / cbt / agents.py View on Github external
build(opt)
    suffix = ''
    dt = opt['datatype'].split(':')[0]
    if dt == 'train':
        suffix = 'train'
    elif dt == 'test':
        suffix = 'test_2500ex'
    elif dt == 'valid':
        suffix = 'valid_2000ex'

    return os.path.join(
        opt['datapath'], 'CBT', 'CBTest', 'data', task + '_' + suffix + '.txt'
    )


class NETeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt['datafile'] = _path('cbtest_NE', opt)
        opt['cloze'] = True
        super().__init__(opt, shared)


class CNTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt['datafile'] = _path('cbtest_CN', opt)
        opt['cloze'] = True
        super().__init__(opt, shared)


class VTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt['datafile'] = _path('cbtest_V', opt)
github facebookresearch / ParlAI / parlai / tasks / wikimovies / agents.py View on Github external
elif dt == 'test':
        suffix = 'test'
    elif dt == 'valid':
        suffix = 'dev'
    return os.path.join(
        opt['datapath'],
        'WikiMovies',
        'movieqa',
        'questions',
        'wiki_entities',
        'wiki-entities_qa_{suffix}.txt'.format(suffix=suffix),
    )


# The knowledge base of facts that can be used to answer questions.
class KBTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        build(opt)
        task = opt.get('task')
        if not task:
            task = 'wikimovies:KB:kb'
        kb = task.split(':')
        if len(kb) == 3:
            kb = kb[2]
        elif len(kb) == 2:
            # default to 'kb' if 'kb', 'wiki', or 'ie' not specified
            kb = 'kb'
        kbs = {}
        kbs['kb'] = os.path.join('wiki_entities', 'wiki_entities_kb.txt')
        kbs['wiki'] = 'wiki.txt'
        kbs['ie'] = 'wiki_ie.txt'
        opt['datafile'] = os.path.join(
github facebookresearch / ParlAI / parlai / tasks / dialog_babi / agents.py View on Github external
elif dt == 'valid':
        suffix = 'dev'
    datafile = os.path.join(
        prefix, '{tsk}-{type}.txt'.format(tsk=tasks[int(task)], type=suffix)
    )

    if opt['task'].split(':')[2] != '6':
        cands_datafile = os.path.join(prefix, 'dialog-babi-candidates.txt')
    else:
        cands_datafile = os.path.join(prefix, 'dialog-babi-task6-dstc2-candidates.txt')

    return datafile, cands_datafile


# The knowledge base of facts that can be used to answer questions.
class KBTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        build(opt)
        opt['datafile'] = os.path.join(
            opt['datapath'],
            'dialog-bAbI',
            'dialog-bAbI-tasks',
            'dialog-babi-kb-all.txt',
        )
        super().__init__(opt, shared)


# Single task.
class TaskTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        paths = _path(opt['task'].split(':')[2], opt)
        opt['datafile'], opt['cands_datafile'] = paths
github facebookresearch / ParlAI / parlai / tasks / scan / agents.py View on Github external
from parlai.core.teachers import FbDialogTeacher
from .build import build

import copy
import os


def _path(opt):
    # Build the data if it doesn't exist.
    build(opt)
    dt = opt['datatype'].split(':')[0]
    return os.path.join(opt['datapath'], 'SCAN', dt + '.txt')


class DefaultTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt)
        super().__init__(opt, shared)
github facebookresearch / ParlAI / projects / memnn_feedback / tasks / dbll_babi / agents.py View on Github external
else:
                        split.append(reward)
                    if start:
                        yield split, True
                        start = False
                    else:
                        yield split, False
                    # reset x in case there is unlabeled data still left
                    x = ''
                    reward = 0
                    y = None
                    read_feedback = False


# Defaults to task 2 with p=0.5.
class DefaultTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        task = '2_p0.5'
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(os.path.join('babi', 'babi1'), task, opt)
        opt['cands_datafile'] = _path(os.path.join('babi', 'babi1'), task, opt, 'train')
        super().__init__(opt, shared)
github facebookresearch / ParlAI / parlai / tasks / personachat / agents.py View on Github external
opt['datafile'] = _path(opt, 'self_revised')
        super().__init__(opt, shared)


class OtherOriginalTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt, 'other_original')
        super().__init__(opt, shared)


class OtherTeacher(OtherOriginalTeacher):
    pass


class OtherRevisedTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt, 'other_revised')
        super().__init__(opt, shared)


class BothOriginalTeacher(FbDialogTeacher):
    def __init__(self, opt, shared=None):
        opt = copy.deepcopy(opt)
        opt['datafile'] = _path(opt, 'both_original')
        super().__init__(opt, shared)


class BothTeacher(BothOriginalTeacher):
    pass
github facebookresearch / ParlAI / parlai / tasks / moviedialog / agents.py View on Github external
'{t}{s}.txt'.format(t=tasks[int(task)], s=suffix),
    )
    if int(task) == 4:
        if dt == 'train':
            candpath = None
        else:
            candpath = datafile.replace(suffix + '.txt', 'cand-{dt}.txt'.format(dt=dt))
    else:
        candpath = os.path.join(
            opt['datapath'], 'MovieDialog', 'movie_dialog_dataset', 'entities.txt'
        )
    return datafile, candpath


# The knowledge base of facts that can be used to answer questions.
class KBTeacher(FbDialogTeacher):
    """Simple text entry with each movie's facts in the knowledge base."""

    def __init__(self, opt, shared=None):
        """Initialize teacher."""
        build(opt)
        opt['datafile'] = os.path.join(
            opt['datapath'], 'MovieDialog', 'movie_dialog_dataset', 'movie_kb.txt'
        )
        super().__init__(opt, shared)


# Single task.
class TaskTeacher(FbDialogTeacher):
    """Teacher with single task, specified by moviedialog:task:N."""

    def __init__(self, opt, shared=None):