Esempio n. 1
0
def row_to_sample(row, column_info, model_type="wide_n_deep"):
    wide_tensor = get_wide_tensor(row, column_info)
    deep_tensor = JTensor.from_ndarray(get_deep_tensor(row, column_info))
    label = row[column_info.label]
    model_type = model_type.lower()
    if model_type == "wide_n_deep":
        feature = [wide_tensor, deep_tensor]
    elif model_type == "wide":
        feature = wide_tensor
    elif model_type == "deep":
        feature = deep_tensor
    else:
        raise TypeError("Unsupported model_type: %s" % model_type)
    return Sample.from_jtensor(feature, label)
Esempio n. 2
0
def row_to_sample(row, column_info, model_type="wide_n_deep"):
    wide_tensor = get_wide_tensor(row, column_info)
    deep_tensor = JTensor.from_ndarray(get_deep_tensor(row, column_info))
    label = row[column_info.label]
    model_type = model_type.lower()
    if model_type == "wide_n_deep":
        feature = [wide_tensor, deep_tensor]
    elif model_type == "wide":
        feature = wide_tensor
    elif model_type == "deep":
        feature = deep_tensor
    else:
        raise TypeError("Unsupported model_type: %s" % model_type)
    return Sample.from_jtensor(feature, label)
Esempio n. 3
0
def row_to_sample(row, column_info, model_type="wide_n_deep"):
    """
    convert a row to sample given column feature information of a WideAndDeep model

    :param row: Row of userId, itemId, features and label
    :param column_info: ColumnFeatureInfo specify information of different features
    :return: TensorSample as input for WideAndDeep model
    """

    wide_tensor = get_wide_tensor(row, column_info)
    deep_tensor = get_deep_tensors(row, column_info)
    deep_tensors = [JTensor.from_ndarray(ele) for ele in deep_tensor]
    label = row[column_info.label]
    model_type = model_type.lower()
    if model_type == "wide_n_deep":
        feature = [wide_tensor] + deep_tensors
    elif model_type == "wide":
        feature = wide_tensor
    elif model_type == "deep":
        feature = deep_tensors
    else:
        raise TypeError("Unsupported model_type: %s" % model_type)
    return Sample.from_jtensor(feature, label)