curiosity-ai / catalyst

🚀 Catalyst is a C# Natural Language Processing library built for speed. Inspired by spaCy's design, it brings pre-trained models, out-of-the box support for training word and document embeddings, and flexible entity recognition models.
MIT License
699 stars 71 forks source link

Blazor is not supported #81

Closed kant2002 closed 1 year ago

kant2002 commented 1 year ago

Describe the bug When running under blazor, you cannot register English language models because you receive this error message

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'UID.Hashes' threw an exception.
 ---> System.PlatformNotSupportedException: System.Security.Cryptography.Csp is not supported on this platform.
   at System.Security.Cryptography.RNGCryptoServiceProvider..ctor()
   at UID.Hashes..cctor()
   --- End of inner exception stack trace ---
   at Catalyst.Models.AveragePerceptronTagger..cctor()
System.AggregateException: One or more errors occurred. (The type initializer for 'Catalyst.Models.AveragePerceptronTagger' threw an exception.)
 ---> System.TypeInitializationException: The type initializer for 'Catalyst.Models.AveragePerceptronTagger' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'UID.Hashes' threw an exception.
 ---> System.PlatformNotSupportedException: System.Security.Cryptography.Csp is not supported on this platform.
   at System.Security.Cryptography.RNGCryptoServiceProvider..ctor()
   at UID.Hashes..cctor()
   --- End of inner exception stack trace ---
   at Catalyst.Models.AveragePerceptronTagger..cctor()
   --- End of inner exception stack trace ---
   at Catalyst.Models.English.Register()

Blazor supports this code:

var random = RandomNumberGenerator.Create();

so I think if repackage Mosaic.Core with Blazor support would simply works. Maybe adding support for browser platform would be needed on Catalys package too.

To Reproduce Just call Catalyst.Models.English.Register(); inside Blazor application

Expected behavior I expect nothing happens and English model would be registered._

Screenshots If applicable, add a code example to help explain your problem.

Additional context

theolivenbaum commented 1 year ago

Hi @kant2002, on a quick check, we can't just replace it because the RNGCryptoServiceProvider used is thread safe, while the RandomNumberGenerator is not (and thread safety is important on this class).

As Blazor is not a supported platform for Catalyst today, (and I'm sure there will be other issues besides this) I'll close this as won't fix for now.

kant2002 commented 8 months ago

Would you reevaluate this decision? I'm basically want to work in browser and use this library https://github.com/kant2002/EngLang/pull/35 I technically can perform surgery fix on my fork, but really want to eventually merge it upstream, since consuming fork via Nuget is painful usually.

I believe these limitation is not somewhich which I cannot overcome, if you in principle eventually want to support WASM/WASI workloads.