def as_nql(
      self,
      expr,
      type_name,
      provenance = None
  ):
    """Convert a Tensorflow expression to a NeuralQueryExpression.

    Args:
      expr: a Tensorflow expression which evaluates to a dense matrix of size
        N*M, where M is the minibatch size, and N is the max id for the named
        type.  Alternatively, expr can be a NeuralQueryExpression, which will be
        typechecked and returned unchanged
      type_name: string naming a type
      provenance: if provided, an NQExprProvenance object

    Returns:
      A NeuralQueryExpression

    Raises:
      TypeNameError: If type_name is not a known type.
      TypeCompatibilityError: If expression is not of type_name type.
      TypeError: If the factory method returned an unexpected type.
    """
    if isinstance(expr, NeuralQueryExpression):
      if expr.type_name != type_name:
        raise TypeCompatibilityError(expr.type_name, type_name, 'as_nql')
      return expr
    else:
      tf_expr = expr
      result = self.expression_factory_class(
          self, tf_expr, type_name, provenance=provenance)
      if not isinstance(result, NeuralQueryExpression):
        raise TypeError(
            'Factory returned %r instead of a NeuralQueryExpression:' %
            type(result))
      return result
Convert a Tensorflow expression to a NeuralQueryExpression.

    Args:
      expr: a Tensorflow expression which evaluates to a dense matrix of size
        N*M, where M is the minibatch size, and N is the max id for the named
        type.  Alternatively, expr can be a NeuralQueryExpression, which will be
        typechecked and returned unchanged
      type_name: string naming a type
      provenance: if provided, an NQExprProvenance object

    Returns:
      A NeuralQueryExpression

    Raises:
      TypeNameError: If type_name is not a known type.
      TypeCompatibilityError: If expression is not of type_name type.
      TypeError: If the factory method returned an unexpected type.
    
language/nql/nql/__init__.py