Search in sources :

Example 11 with ExpressionNode

use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.

the class GBDTForestOptimizer method findAndOptimize.

/**
 * Recursively descend and optimize gbdt forest nodes.
 *
 * @return the resulting node, which may be the input node if no optimizations were found
 */
private ExpressionNode findAndOptimize(ExpressionNode node) {
    ExpressionNode newNode = optimize(node);
    // 
    if (!(newNode instanceof CompositeNode))
        return newNode;
    CompositeNode newComposite = (CompositeNode) newNode;
    List<ExpressionNode> newChildren = new ArrayList<>();
    for (ExpressionNode child : newComposite.children()) {
        newChildren.add(findAndOptimize(child));
    }
    return newComposite.setChildren(newChildren);
}
Also used : CompositeNode(com.yahoo.searchlib.rankingexpression.rule.CompositeNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList)

Example 12 with ExpressionNode

use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.

the class MacroShadower method transform.

@Override
public RankingExpression transform(RankingExpression expression, RankProfileTransformContext context) {
    String name = expression.getName();
    ExpressionNode node = expression.getRoot();
    ExpressionNode result = transform(node, context);
    return new RankingExpression(name, result);
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)

Example 13 with ExpressionNode

use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.

the class TensorFlowFeatureConverter method reduceBatchDimensionsAtInput.

private ExpressionNode reduceBatchDimensionsAtInput(ExpressionNode node, TensorFlowModel model, TypeContext<Reference> typeContext) {
    if (node instanceof TensorFunctionNode) {
        TensorFunction tensorFunction = ((TensorFunctionNode) node).function();
        if (tensorFunction instanceof Rename) {
            List<ExpressionNode> children = ((TensorFunctionNode) node).children();
            if (children.size() == 1 && children.get(0) instanceof ReferenceNode) {
                ReferenceNode referenceNode = (ReferenceNode) children.get(0);
                if (model.requiredMacros().containsKey(referenceNode.getName())) {
                    return reduceBatchDimensionExpression(tensorFunction, typeContext);
                }
            }
        }
    }
    if (node instanceof ReferenceNode) {
        ReferenceNode referenceNode = (ReferenceNode) node;
        if (model.requiredMacros().containsKey(referenceNode.getName())) {
            return reduceBatchDimensionExpression(TensorFunctionNode.wrapArgument(node), typeContext);
        }
    }
    if (node instanceof CompositeNode) {
        List<ExpressionNode> children = ((CompositeNode) node).children();
        List<ExpressionNode> transformedChildren = new ArrayList<>(children.size());
        for (ExpressionNode child : children) {
            transformedChildren.add(reduceBatchDimensionsAtInput(child, model, typeContext));
        }
        return ((CompositeNode) node).setChildren(transformedChildren);
    }
    return node;
}
Also used : CompositeNode(com.yahoo.searchlib.rankingexpression.rule.CompositeNode) TensorFunctionNode(com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode) TensorFunction(com.yahoo.tensor.functions.TensorFunction) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList) Rename(com.yahoo.tensor.functions.Rename)

Example 14 with ExpressionNode

use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.

the class MapEvaluationTypeContext method tensorFeatureType.

/**
 * There are two features which returns the (non-empty) tensor type: tensorFromLabels and tensorFromWeightedSet.
 * This returns the type of those features if this is a reference to either of them, or empty otherwise.
 */
private Optional<TensorType> tensorFeatureType(Reference reference) {
    if (!reference.name().equals("tensorFromLabels") && !reference.name().equals("tensorFromWeightedSet"))
        return Optional.empty();
    if (reference.arguments().size() != 1 && reference.arguments().size() != 2)
        throw new IllegalArgumentException(reference.name() + " must have one or two arguments");
    ExpressionNode arg0 = reference.arguments().expressions().get(0);
    if (!(arg0 instanceof ReferenceNode) || !FeatureNames.isSimpleFeature(((ReferenceNode) arg0).reference()))
        throw new IllegalArgumentException("The first argument of " + reference.name() + " must be a simple feature, not " + arg0);
    String dimension;
    if (reference.arguments().size() > 1) {
        ExpressionNode arg1 = reference.arguments().expressions().get(1);
        if ((!(arg1 instanceof ReferenceNode) || !(((ReferenceNode) arg1).reference().isIdentifier())) && (!(arg1 instanceof NameNode)))
            throw new IllegalArgumentException("The second argument of " + reference.name() + " must be a dimension name, not " + arg1);
        dimension = reference.arguments().expressions().get(1).toString();
    } else {
        // default
        dimension = ((ReferenceNode) arg0).reference().arguments().expressions().get(0).toString();
    }
    return Optional.of(new TensorType.Builder().mapped(dimension).build());
}
Also used : NameNode(com.yahoo.searchlib.rankingexpression.rule.NameNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) TensorType(com.yahoo.tensor.TensorType)

Example 15 with ExpressionNode

use of com.yahoo.searchlib.rankingexpression.rule.ExpressionNode in project vespa by vespa-engine.

the class TensorTransformer method replaceMaxAndMinFunction.

private ExpressionNode replaceMaxAndMinFunction(FunctionNode node) {
    ExpressionNode arg1 = node.children().get(0);
    ExpressionNode arg2 = node.children().get(1);
    TensorFunctionNode.TensorFunctionExpressionNode expression = TensorFunctionNode.wrapArgument(arg1);
    Reduce.Aggregator aggregator = Reduce.Aggregator.valueOf(node.getFunction().name());
    String dimension = ((ReferenceNode) arg2).getName();
    return new TensorFunctionNode(new Reduce(expression, aggregator, dimension));
}
Also used : TensorFunctionNode(com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) Reduce(com.yahoo.tensor.functions.Reduce)

Aggregations

ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)21 TensorType (com.yahoo.tensor.TensorType)8 ArrayList (java.util.ArrayList)7 DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)6 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)6 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)6 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)5 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)4 ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)4 CompositeNode (com.yahoo.searchlib.rankingexpression.rule.CompositeNode)4 GeneratorLambdaFunctionNode (com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode)4 Generate (com.yahoo.tensor.functions.Generate)4 ArithmeticOperator (com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)3 Reduce (com.yahoo.tensor.functions.Reduce)3 TensorFunction (com.yahoo.tensor.functions.TensorFunction)3 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)2 RankProfile (com.yahoo.searchdefinition.RankProfile)1 Reference (com.yahoo.searchlib.rankingexpression.Reference)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 ComparisonNode (com.yahoo.searchlib.rankingexpression.rule.ComparisonNode)1