Search in sources :

Example 1 with RecommMapper

use of com.alibaba.alink.operator.common.recommendation.RecommMapper in project Alink by alibaba.

the class BaseRecommender method collectLocalPredictor.

@Override
public LocalPredictor collectLocalPredictor(TableSchema inputSchema) {
    List<Row> modelRows = this.modelData.collect();
    ModelMapper mapper = new RecommMapper(this.recommKernelBuilder, this.recommType, modelData.getSchema(), inputSchema, this.getParams());
    mapper.loadModel(modelRows);
    return new LocalPredictor(mapper);
}
Also used : LocalPredictor(com.alibaba.alink.pipeline.LocalPredictor) Row(org.apache.flink.types.Row) RecommMapper(com.alibaba.alink.operator.common.recommendation.RecommMapper) ModelMapper(com.alibaba.alink.common.mapper.ModelMapper)

Example 2 with RecommMapper

use of com.alibaba.alink.operator.common.recommendation.RecommMapper in project Alink by alibaba.

the class BaseRecommStreamOp method linkFrom.

@Override
public T linkFrom(StreamOperator<?>... inputs) {
    StreamOperator<?> in = checkAndGetFirst(inputs);
    TableSchema modelSchema = this.model.getSchema();
    try {
        DataBridge modelDataBridge = DirectReader.collect(model);
        DataBridgeModelSource modelSource = new DataBridgeModelSource(modelDataBridge);
        RecommMapper mapper = new RecommMapper(this.recommKernelBuilder, this.recommType, modelSchema, in.getSchema(), this.getParams());
        DataStream<Row> resultRows;
        if (getParams().get(ModelMapperParams.NUM_THREADS) <= 1) {
            resultRows = in.getDataStream().map(new RecommAdapter(mapper, modelSource));
        } else {
            resultRows = in.getDataStream().flatMap(new RecommAdapterMT(mapper, modelSource, getParams().get(ModelMapperParams.NUM_THREADS)));
        }
        TableSchema outputSchema = mapper.getOutputSchema();
        this.setOutput(resultRows, outputSchema);
        return (T) this;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : RecommAdapter(com.alibaba.alink.operator.common.recommendation.RecommAdapter) TableSchema(org.apache.flink.table.api.TableSchema) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) DataBridgeModelSource(com.alibaba.alink.common.model.DataBridgeModelSource) Row(org.apache.flink.types.Row) RecommMapper(com.alibaba.alink.operator.common.recommendation.RecommMapper) DataBridge(com.alibaba.alink.common.io.directreader.DataBridge)

Example 3 with RecommMapper

use of com.alibaba.alink.operator.common.recommendation.RecommMapper in project Alink by alibaba.

the class BaseRecommBatchOp method linkFrom.

@Override
public T linkFrom(BatchOperator<?>... inputs) {
    checkOpSize(2, inputs);
    try {
        BroadcastVariableModelSource modelSource = new BroadcastVariableModelSource(BROADCAST_MODEL_TABLE_NAME);
        RecommMapper mapper = new RecommMapper(this.recommKernelBuilder, this.recommType, inputs[0].getSchema(), inputs[1].getSchema(), this.getParams());
        DataSet<Row> modelRows = inputs[0].getDataSet().rebalance();
        DataSet<Row> resultRows;
        if (getParams().get(ModelMapperParams.NUM_THREADS) <= 1) {
            resultRows = inputs[1].getDataSet().map(new RecommAdapter(mapper, modelSource)).withBroadcastSet(modelRows, BROADCAST_MODEL_TABLE_NAME);
        } else {
            resultRows = inputs[1].getDataSet().flatMap(new RecommAdapterMT(mapper, modelSource, getParams().get(ModelMapperParams.NUM_THREADS))).withBroadcastSet(modelRows, BROADCAST_MODEL_TABLE_NAME);
        }
        TableSchema outputSchema = mapper.getOutputSchema();
        this.setOutput(resultRows, outputSchema);
        return (T) this;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : RecommAdapter(com.alibaba.alink.operator.common.recommendation.RecommAdapter) BroadcastVariableModelSource(com.alibaba.alink.common.model.BroadcastVariableModelSource) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) TableSchema(org.apache.flink.table.api.TableSchema) RecommAdapterMT(com.alibaba.alink.operator.common.recommendation.RecommAdapterMT) Row(org.apache.flink.types.Row) RecommMapper(com.alibaba.alink.operator.common.recommendation.RecommMapper)

Aggregations

RecommMapper (com.alibaba.alink.operator.common.recommendation.RecommMapper)3 Row (org.apache.flink.types.Row)3 RecommAdapter (com.alibaba.alink.operator.common.recommendation.RecommAdapter)2 RecommAdapterMT (com.alibaba.alink.operator.common.recommendation.RecommAdapterMT)2 TableSchema (org.apache.flink.table.api.TableSchema)2 DataBridge (com.alibaba.alink.common.io.directreader.DataBridge)1 ModelMapper (com.alibaba.alink.common.mapper.ModelMapper)1 BroadcastVariableModelSource (com.alibaba.alink.common.model.BroadcastVariableModelSource)1 DataBridgeModelSource (com.alibaba.alink.common.model.DataBridgeModelSource)1 LocalPredictor (com.alibaba.alink.pipeline.LocalPredictor)1