def forward(model: Tok2VecListener, inputs, is_train: bool):
    """Supply the outputs from the upstream Tok2Vec component."""
    if is_train:
        # This might occur during training when the tok2vec layer is frozen / hasn't been updated.
        # In that case, it should be set to "annotating" so we can retrieve the embeddings from the doc.
        if model._batch_id is None:
            outputs = []
            for doc in inputs:
                if doc.tensor.size == 0:
                    raise ValueError(Errors.E203.format(name="tok2vec"))
                else:
                    outputs.append(doc.tensor)
            return outputs, _empty_backprop
        else:
            model.verify_inputs(inputs)
            return model._outputs, model._backprop
    else:
        # This is pretty grim, but it's hard to do better :(.
        # It's hard to avoid relying on the doc.tensor attribute, because the
        # pipeline components can batch the data differently during prediction.
        # That doesn't happen in update, where the nlp object works on batches
        # of data.
        # When the components batch differently, we don't receive a matching
        # prediction from the upstream, so we can't predict.
        outputs = []
        width = model.get_dim("nO")
        for doc in inputs:
            if doc.tensor.size == 0:
                # But we do need to do *something* if the tensor hasn't been set.
                # The compromise is to at least return data of the right shape,
                # so the output is valid.
                outputs.append(model.ops.alloc2f(len(doc), width))
            else:
                outputs.append(doc.tensor)
        return outputs, _empty_backprop
Supply the outputs from the upstream Tok2Vec component.
spacy/pipeline/tok2vec.py