Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
36e98dd
Initial plan
Copilot Mar 20, 2026
f3b6af6
Remove AutoMapper dependency, replace with manual property mapping
Copilot Mar 20, 2026
ceca995
Merge pull request #1 from crispthinking/copilot/remove-automapper-de…
corpo-iwillspeak Mar 20, 2026
7290ad6
Initial plan
Copilot Apr 1, 2026
75cb70d
Initial plan
Copilot Apr 1, 2026
3d6f17b
Remove AutoMapper dependency from nuspec file
Copilot Apr 1, 2026
215dc18
Initial plan
Copilot Apr 1, 2026
1a6e9b3
Remove AutoMapper dependency from nuspec
Copilot Apr 1, 2026
cd4517b
Merge pull request #2 from crispthinking/copilot/remove-automapper-re…
corpo-iwillspeak Apr 1, 2026
0253a3d
Add ci.yml skeleton
Copilot Apr 1, 2026
340da68
Switch to 2-stage CI/Publish workflow with MinVer and CrispThinking p…
Copilot Apr 1, 2026
b51c881
Fix CVE: pin actions/download-artifact to v4.1.3 to patch arbitrary f…
Copilot Apr 1, 2026
5626d73
Merge pull request #3 from crispthinking/copilot/remove-references-to…
corpo-iwillspeak Apr 1, 2026
94867f2
Port NuGet publish step to use trusted publishing (OIDC) instead of A…
Copilot Apr 1, 2026
1bc9b27
Use NuGet/login@v1 action instead of manual OIDC curl for trusted pub…
Copilot Apr 1, 2026
5ea855a
Merge pull request #4 from crispthinking/copilot/build-and-publish-fo…
corpo-iwillspeak Apr 1, 2026
4e525da
Fix NuGet API key reference in publish workflow
corpo-iwillspeak Apr 1, 2026
0ea4555
Initial plan
Copilot Apr 1, 2026
5039e24
Fix MinVer version generation by adding fetch-tags: true to checkout …
Copilot Apr 1, 2026
e920cb7
Merge pull request #5 from crispthinking/copilot/fix-minver-configura…
corpo-iwillspeak Apr 1, 2026
72bb5ef
Initial plan
Copilot Apr 1, 2026
b5797d6
Reset master to 3d6f17b: revert extra build fixes
Copilot Apr 1, 2026
2cf4094
Merge pull request #6 from crispthinking/copilot/reset-master-to-3d6f17b
corpo-iwillspeak Apr 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion FastText.NetWrapper/FastText.NetWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="FastText.Native.Linux" Version="1.0.115" />
<PackageReference Include="FastText.Native.MacOs" Version="1.0.115" />
<PackageReference Include="FastText.Native.Windows" Version="1.0.115" />
Expand Down
1 change: 0 additions & 1 deletion FastText.NetWrapper/FastText.NetWrapper.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<repository url="https://github.com/olegtarasov/FastText.NetWrapper" />
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="AutoMapper" version="10.1.1" />
<dependency id="FastText.Native.Linux" version="1.0.115" />
<dependency id="FastText.Native.MacOs" version="1.0.115" />
<dependency id="FastText.Native.Windows" version="1.0.115" />
Expand Down
55 changes: 36 additions & 19 deletions FastText.NetWrapper/FastTextArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.InteropServices;
using AutoMapper;

namespace FastText.NetWrapper;

Expand Down Expand Up @@ -40,8 +39,8 @@ public unsafe QuantizedSupervisedArgs()
FastTextWrapper.FastTextArgsStruct* argsPtr;

GetDefaultSupervisedArgs(new IntPtr(&argsPtr));
Mapper.Map(*argsPtr, this);

MapFromStruct(*argsPtr);

DestroyArgs(new IntPtr(argsPtr));
}
Expand Down Expand Up @@ -87,7 +86,7 @@ public unsafe SupervisedArgs()

GetDefaultSupervisedArgs(new IntPtr(&argsPtr));

Mapper.Map(*argsPtr, this);
MapFromStruct(*argsPtr);

DestroyArgs(new IntPtr(argsPtr));
}
Expand Down Expand Up @@ -120,20 +119,6 @@ public abstract class FastTextArgs

#endregion

protected static readonly IMapper Mapper;

static FastTextArgs()
{
Mapper = new MapperConfiguration(config =>
{
config.ShouldMapProperty = prop => prop.GetMethod.IsPublic || prop.GetMethod.IsAssembly;
config.CreateMap<FastTextWrapper.FastTextArgsStruct, FastTextArgs>();
config.CreateMap<FastTextWrapper.FastTextArgsStruct, SupervisedArgs>();
config.CreateMap<FastTextWrapper.FastTextArgsStruct, UnsupervisedArgs>();
config.CreateMap<FastTextWrapper.FastTextArgsStruct, QuantizedSupervisedArgs>();
}).CreateMapper();
}

/// <summary>
/// This constructor gets values from
/// https://github.com/olegtarasov/fastText/blob/b0a32d744f4d16d8f9834649f6f178ff79b5a4ce/src/fasttext_api.cc#L12
Expand All @@ -146,11 +131,43 @@ protected unsafe FastTextArgs()

GetDefaultArgs(new IntPtr(&argsPtr));

Mapper.Map(*argsPtr, this);
MapFromStruct(*argsPtr);

DestroyArgs(new IntPtr(argsPtr));
}

protected void MapFromStruct(FastTextWrapper.FastTextArgsStruct argsStruct)
{
lr = argsStruct.lr;
lrUpdateRate = argsStruct.lrUpdateRate;
dim = argsStruct.dim;
ws = argsStruct.ws;
epoch = argsStruct.epoch;
minCount = argsStruct.minCount;
minCountLabel = argsStruct.minCountLabel;
neg = argsStruct.neg;
wordNgrams = argsStruct.wordNgrams;
loss = (LossName)argsStruct.loss;
model = (ModelName)argsStruct.model;
bucket = argsStruct.bucket;
minn = argsStruct.minn;
maxn = argsStruct.maxn;
thread = argsStruct.thread;
t = argsStruct.t;
verbose = argsStruct.verbose;
saveOutput = argsStruct.saveOutput;
seed = argsStruct.seed;

if (this is QuantizedSupervisedArgs quantized)
{
quantized.qout = argsStruct.qout;
quantized.retrain = argsStruct.retrain;
quantized.qnorm = argsStruct.qnorm;
quantized.cutoff = argsStruct.cutoff;
quantized.dsub = argsStruct.dsub;
}
}

/// <summary>
/// learning rate [0.1]
/// </summary>
Expand Down
82 changes: 54 additions & 28 deletions FastText.NetWrapper/FastTextWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Runtime.InteropServices;
using System.Text;
using AutoMapper;
using Microsoft.Extensions.Logging;

namespace FastText.NetWrapper;
Expand All @@ -12,7 +11,6 @@ public partial class FastTextWrapper : IDisposable
{
private static readonly Encoding _utf8 = Encoding.UTF8;

private readonly IMapper _mapper;
private readonly ILogger<FastTextWrapper> _logger;

private IntPtr _fastText;
Expand All @@ -25,17 +23,6 @@ public partial class FastTextWrapper : IDisposable
public FastTextWrapper(ILoggerFactory loggerFactory = null)
{
_logger = loggerFactory?.CreateLogger<FastTextWrapper>();

_mapper = new MapperConfiguration(config =>
{
config.ShouldMapProperty = prop => prop.GetMethod.IsPublic || prop.GetMethod.IsAssembly;
config.CreateMap<SupervisedArgs, FastTextArgsStruct>();
config.CreateMap<QuantizedSupervisedArgs, FastTextArgsStruct>();
config.CreateMap<UnsupervisedArgs, FastTextArgsStruct>();
config.CreateMap<AutotuneArgs, AutotuneArgsStruct>();
})
.CreateMapper();

_fastText = CreateFastText();
}

Expand All @@ -54,17 +41,6 @@ public FastTextWrapper(ILoggerFactory loggerFactory = null)
public FastTextWrapper(bool useBundledLibrary, ILoggerFactory loggerFactory = null)
{
_logger = loggerFactory?.CreateLogger<FastTextWrapper>();

_mapper = new MapperConfiguration(config =>
{
config.ShouldMapProperty = prop => prop.GetMethod.IsPublic || prop.GetMethod.IsAssembly;
config.CreateMap<SupervisedArgs, FastTextArgsStruct>();
config.CreateMap<QuantizedSupervisedArgs, FastTextArgsStruct>();
config.CreateMap<UnsupervisedArgs, FastTextArgsStruct>();
config.CreateMap<AutotuneArgs, AutotuneArgsStruct>();
})
.CreateMapper();

_fastText = CreateFastText();
}

Expand Down Expand Up @@ -220,10 +196,10 @@ internal void Supervised(string inputPath, string outputPath, SupervisedArgs arg

bool quantizeWithNoQuantTune = quantizedArgs != null && string.IsNullOrEmpty(autotuneArgs.ModelSize);

var argsStruct = _mapper.Map<FastTextArgsStruct>(args);
var argsStruct = ToArgsStruct(args);
argsStruct.model = model_name.sup;

var autotuneStruct = _mapper.Map<AutotuneArgsStruct>(autotuneArgs);
var autotuneStruct = ToAutotuneArgsStruct(autotuneArgs);
CheckForErrors(Train(
_fastText,
inputPath,
Expand Down Expand Up @@ -273,7 +249,7 @@ public void Unsupervised(UnsupervisedModel model, string inputPath, string outpu

args.model = (ModelName)model;

var argsStruct = _mapper.Map<FastTextArgsStruct>(args);
var argsStruct = ToArgsStruct(args);
CheckForErrors(Train(
_fastText,
inputPath,
Expand Down Expand Up @@ -305,7 +281,7 @@ public void Quantize(QuantizedSupervisedArgs args, string output = null)
if (string.IsNullOrEmpty(ModelPath) && string.IsNullOrEmpty(output))
throw new InvalidOperationException("Model was loaded from memory. You need to specify output path.");

var argsStruct = _mapper.Map<FastTextArgsStruct>(args);
var argsStruct = ToArgsStruct(args);
string outPath = AdjustPath(string.IsNullOrEmpty(output) ? ModelPath : output, true);

if ((Path.IsPathRooted(output) && !Directory.Exists(Path.GetDirectoryName(outPath))))
Expand Down Expand Up @@ -502,6 +478,56 @@ public void Dispose()
_fastText = IntPtr.Zero;
}

private static FastTextArgsStruct ToArgsStruct(FastTextArgs args)
{
var result = new FastTextArgsStruct
{
lr = args.lr,
lrUpdateRate = args.lrUpdateRate,
dim = args.dim,
ws = args.ws,
epoch = args.epoch,
minCount = args.minCount,
minCountLabel = args.minCountLabel,
neg = args.neg,
wordNgrams = args.wordNgrams,
loss = (loss_name)args.loss,
model = (model_name)args.model,
bucket = args.bucket,
minn = args.minn,
maxn = args.maxn,
thread = args.thread,
t = args.t,
verbose = args.verbose,
saveOutput = args.saveOutput,
seed = args.seed
};

if (args is QuantizedSupervisedArgs quantized)
{
result.qout = quantized.qout;
result.retrain = quantized.retrain;
result.qnorm = quantized.qnorm;
result.cutoff = quantized.cutoff;
result.dsub = quantized.dsub;
}

return result;
}

private static AutotuneArgsStruct ToAutotuneArgsStruct(AutotuneArgs args)
{
return new AutotuneArgsStruct
{
ValidationFile = args.ValidationFile,
Metric = args.Metric,
Predictions = args.Predictions,
Duration = args.Duration,
ModelSize = args.ModelSize,
Verbose = args.Verbose
};
}

private string AdjustPath(string path, bool isQuantized)
{
string result = Path.HasExtension(path) ? Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)) : path;
Expand Down