private BindingsImpl(DataViewSchema input, ISchemaBoundRowMapper mapper, string suffix, string scoreColumnKind, bool user, int scoreColIndex, DataViewType predColType, string predictedLabelColumnName = DefaultColumnNames.PredictedLabel) : base(input, mapper, suffix, user, predictedLabelColumnName) { Contracts.AssertNonEmpty(scoreColumnKind); Contracts.Assert(DerivedColumnCount == 1); ScoreColumnIndex = scoreColIndex; ScoreColumnKind = scoreColumnKind; PredColType = predColType; _getScoreColumnKind = GetScoreColumnKind; _getScoreValueKind = GetScoreValueKind; // REVIEW: This logic is very specific to multiclass, which is deeply // regrettable, but the class structure as designed and the status of this schema // bearing object makes pushing the logic into the multiclass scorer almost impossible. if (predColType is KeyDataViewType predColKeyType && predColKeyType.Count > 0) { var scoreColMetadata = mapper.OutputSchema[scoreColIndex].Annotations; var trainLabelColumn = scoreColMetadata.Schema.GetColumnOrNull(AnnotationUtils.Kinds.TrainingLabelValues); if (trainLabelColumn?.Type is VectorDataViewType trainLabelColVecType && (ulong)trainLabelColVecType.Size == predColKeyType.Count) { Contracts.Assert(trainLabelColVecType.Size > 0); _predColMetadata = Utils.MarshalInvoke(_keyValueMetadataFromMetadataMethodInfo, trainLabelColVecType.RawType, scoreColMetadata, trainLabelColumn.Value); } } }
public GetterInfoDelegate(string kind, DataViewType type, AnnotationUtils.AnnotationGetter <TValue> getter) : base(kind, type) { Contracts.Check(type.RawType == typeof(TValue), "Incompatible types"); Contracts.CheckValue(getter, nameof(getter)); Getter = getter; }
public Bindings(IExceptionContext ectx, DataViewSchema input, bool user, string labelCol, string scoreCol, string groupCol, int truncationLevel) : base(ectx, input, labelCol, scoreCol, groupCol, user, Ndcg, Dcg, MaxDcg) { _truncationLevel = truncationLevel; _outputType = new VectorDataViewType(NumberDataViewType.Double, _truncationLevel); _slotNamesType = new VectorDataViewType(TextDataViewType.Instance, _truncationLevel); _slotNamesGetter = SlotNamesGetter; }
/// <summary> /// Add metadata of the given kind. When requested, the metadata is fetched by calling the given delegate. /// </summary> public void AddGetter <TValue>(string kind, DataViewType type, AnnotationUtils.AnnotationGetter <TValue> getter) { Contracts.Check(_md != null, "Builder disposed"); Contracts.CheckNonEmpty(kind, nameof(kind)); Contracts.CheckValue(type, nameof(type)); Contracts.CheckValue(getter, nameof(getter)); Contracts.CheckParam(type.RawType == typeof(TValue), nameof(type), "Given type doesn't match type parameter"); if (_getters != null && _getters.Any(g => g.Kind == kind)) { throw Contracts.Except("Duplicate specification of metadata"); } Utils.Add(ref _getters, new GetterInfoDelegate <TValue>(kind, type, getter)); }
protected ScorerBindingsBase(DataViewSchema input, ISchemaBoundMapper mapper, string suffix, bool user, params string[] namesDerived) : base(input, user, GetOutputNames(mapper, suffix, namesDerived)) { Contracts.AssertValue(mapper); Contracts.AssertValueOrNull(suffix); Contracts.AssertValue(namesDerived); Mapper = mapper; DerivedColumnCount = namesDerived.Length; Suffix = suffix ?? ""; int c; var max = input.GetMaxAnnotationKind(out c, AnnotationUtils.Kinds.ScoreColumnSetId); _crtScoreSet = checked (max + 1); _getScoreColumnSetId = GetScoreColumnSetId; }
public Impl(IHostEnvironment env, string name, IDataView input, OneToOneColumn col, DataViewType typeDst, ValueMapper <T1, T2> map1, ValueMapper <T2, T3> map2 = null, ValueGetter <VBuffer <ReadOnlyMemory <char> > > keyValueGetter = null, ValueGetter <VBuffer <ReadOnlyMemory <char> > > slotNamesGetter = null) : base(env, name, new[] { col }, input, x => null) { Host.Assert(typeDst.RawType == typeof(T3)); Host.AssertValue(map1); Host.Assert(map2 != null || typeof(T2) == typeof(T3)); _typeDst = typeDst; _map1 = map1; _map2 = map2; if (keyValueGetter != null || slotNamesGetter != null) { using (var bldr = Metadata.BuildMetadata(0)) { if (keyValueGetter != null) { AnnotationUtils.AnnotationGetter <VBuffer <ReadOnlyMemory <char> > > mdGetter = (int c, ref VBuffer <ReadOnlyMemory <char> > dst) => keyValueGetter(ref dst); bldr.AddGetter(AnnotationUtils.Kinds.KeyValues, new VectorType(TextDataViewType.Instance, _typeDst.GetItemType().GetKeyCountAsInt32(Host)), mdGetter); } if (slotNamesGetter != null) { int vectorSize = _typeDst.GetVectorSize(); Host.Assert(vectorSize > 0); AnnotationUtils.AnnotationGetter <VBuffer <ReadOnlyMemory <char> > > mdGetter = (int c, ref VBuffer <ReadOnlyMemory <char> > dst) => slotNamesGetter(ref dst); bldr.AddGetter(AnnotationUtils.Kinds.SlotNames, new VectorType(TextDataViewType.Instance, vectorSize), mdGetter); } } } Metadata.Seal(); }