Search in sources :

Example 6 with DoubleValue

use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.

the class Reshape method unrollTensorExpression.

private static ExpressionNode unrollTensorExpression(TensorType type) {
    if (type.rank() == 0) {
        return new ConstantNode(DoubleValue.zero);
    }
    List<ExpressionNode> children = new ArrayList<>();
    List<ArithmeticOperator> operators = new ArrayList<>();
    int size = 1;
    for (int i = type.dimensions().size() - 1; i >= 0; --i) {
        TensorType.Dimension dimension = type.dimensions().get(i);
        children.add(0, new ReferenceNode(dimension.name()));
        if (size > 1) {
            operators.add(0, ArithmeticOperator.MULTIPLY);
            children.add(0, new ConstantNode(new DoubleValue(size)));
        }
        size *= TensorConverter.dimensionSize(dimension);
        if (i > 0) {
            operators.add(0, ArithmeticOperator.PLUS);
        }
    }
    return new ArithmeticNode(children, operators);
}
Also used : ArithmeticNode(com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) ReferenceNode(com.yahoo.searchlib.rankingexpression.rule.ReferenceNode) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) ArrayList(java.util.ArrayList) ArithmeticOperator(com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator) OrderedTensorType(com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType) TensorType(com.yahoo.tensor.TensorType)

Example 7 with DoubleValue

use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.

the class ExpandDims method lazyGetFunction.

@Override
protected TensorFunction lazyGetFunction() {
    if (!allInputFunctionsPresent(2)) {
        return null;
    }
    // multiply with a generated tensor created from the reduced dimensions
    TensorType.Builder typeBuilder = new TensorType.Builder();
    for (String name : expandDimensions) {
        typeBuilder.indexed(name, 1);
    }
    TensorType generatedType = typeBuilder.build();
    ExpressionNode generatedExpression = new ConstantNode(new DoubleValue(1));
    Generate generatedFunction = new Generate(generatedType, new GeneratorLambdaFunctionNode(generatedType, generatedExpression).asLongListToDoubleOperator());
    return new com.yahoo.tensor.functions.Join(inputs().get(0).function().get(), generatedFunction, ScalarFunctions.multiply());
}
Also used : GeneratorLambdaFunctionNode(com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode) ConstantNode(com.yahoo.searchlib.rankingexpression.rule.ConstantNode) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) ExpressionNode(com.yahoo.searchlib.rankingexpression.rule.ExpressionNode) Generate(com.yahoo.tensor.functions.Generate) OrderedTensorType(com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType) TensorType(com.yahoo.tensor.TensorType)

Example 8 with DoubleValue

use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.

the class ElementCompleteness method compute.

/**
 * Computes the following elementCompleteness features:
 * <ul>
 *     <li><code>completeness</code>
 *     <li><code>fieldCompleteness</code>
 *     <li><code>queryCompleteness</code>
 *     <li><code>elementWeight</code>
 * </ul>
 *
 * @param queryTerms the query terms with associated weights to compute over
 * @param field a set of weighted field values, where each is taken to be a space-separated string of tokens
 * @return a features object containing the values listed above
 */
public static Features compute(Map<String, Integer> queryTerms, Item[] field) {
    double completeness = 0;
    double fieldCompleteness = 0;
    double queryCompleteness = 0;
    double elementWeight = 0;
    double queryTermWeightSum = sum(queryTerms.values());
    for (Item item : field) {
        String[] itemTokens = item.value().split(" ");
        int matchCount = 0;
        int matchWeightSum = 0;
        for (String token : itemTokens) {
            Integer weight = queryTerms.get(token);
            if (weight == null)
                continue;
            matchCount++;
            matchWeightSum += weight;
        }
        double itemFieldCompleteness = (double) matchCount / itemTokens.length;
        double itemQueryCompleteness = matchWeightSum / queryTermWeightSum;
        double itemCompleteness = fieldCompletenessImportance * itemFieldCompleteness + (1 - fieldCompletenessImportance) * itemQueryCompleteness;
        if (itemCompleteness > completeness) {
            completeness = itemCompleteness;
            fieldCompleteness = itemFieldCompleteness;
            queryCompleteness = itemQueryCompleteness;
            elementWeight = item.weight();
        }
    }
    Map<String, Value> features = new HashMap<>();
    features.put("completeness", new DoubleValue(completeness));
    features.put("fieldCompleteness", new DoubleValue(fieldCompleteness));
    features.put("queryCompleteness", new DoubleValue(queryCompleteness));
    features.put("elementWeight", new DoubleValue(elementWeight));
    return new Features(features);
}
Also used : HashMap(java.util.HashMap) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) DoubleValue(com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue) Value(com.yahoo.searchlib.rankingexpression.evaluation.Value)

Aggregations

DoubleValue (com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue)8 ConstantNode (com.yahoo.searchlib.rankingexpression.rule.ConstantNode)5 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)5 TensorType (com.yahoo.tensor.TensorType)4 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)3 GeneratorLambdaFunctionNode (com.yahoo.searchlib.rankingexpression.rule.GeneratorLambdaFunctionNode)3 Generate (com.yahoo.tensor.functions.Generate)3 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)2 ArithmeticNode (com.yahoo.searchlib.rankingexpression.rule.ArithmeticNode)2 ArithmeticOperator (com.yahoo.searchlib.rankingexpression.rule.ArithmeticOperator)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ReferenceNode (com.yahoo.searchlib.rankingexpression.rule.ReferenceNode)1 TensorFunctionNode (com.yahoo.searchlib.rankingexpression.rule.TensorFunctionNode)1 Join (com.yahoo.tensor.functions.Join)1 Reduce (com.yahoo.tensor.functions.Reduce)1 TensorFunction (com.yahoo.tensor.functions.TensorFunction)1 Test (org.junit.Test)1