Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于创建数据处理函数问题 #93

Open
AlexYoung757 opened this issue Nov 11, 2021 · 3 comments
Open

关于创建数据处理函数问题 #93

AlexYoung757 opened this issue Nov 11, 2021 · 3 comments

Comments

@AlexYoung757
Copy link

如题,如果我有多个任务:A、B、C、D那是不是需要创建多个类似A_cls这样的装饰器函数,如下所示:
@preprocessing_fn
def A_cls(params, mode):
# get data
# your work
return input_list, target_list
能否根据具体任务动态的创建数据处理函数呢

@JayYip
Copy link
Owner

JayYip commented Nov 12, 2021 via email

@AlexYoung757
Copy link
Author

创建单任务数据处理函数

def create_fn(problem_list):
# do some
print("do work")

@preprocessing_fn
def example_cls(params, mode):
    train_texts, train_labels = [], []
    test_texts, test_labels = [],[]

    # 训练模型
    if (mode == TRAIN):
        input_list = train_texts
        target_list = train_labels
    else:
        input_list = test_texts
        target_list = test_labels
    
    return input_list, target_list

example_cls.__name__ = problem_list

return example_cls

like this?

@JayYip
Copy link
Owner

JayYip commented Nov 29, 2021

嗯, 看起来差不多, 可能这样构造会好一点

def create_preproc_fns(problem: str) -> Callable:
    @preprocessing_fn
    def example_cls(params, mode):
        train_texts, train_labels = [], []
        test_texts, test_labels = [],[]

        # 训练模型
        if (mode == TRAIN):
            input_list = train_texts
            target_list = train_labels
        else:
            input_list = test_texts
            target_list = test_labels
        
        return input_list, target_list
    example_cls.__name__ = problem
    return example_cls

fn_list = [create_preproc_fns(problem) for problem in ['a', 'b', 'c']]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants