Coder Social home page Coder Social logo

Comments (6)

YuhanLiin avatar YuhanLiin commented on July 30, 2024 1

I don't think CountVectorizer has serde support but it should be pretty easy to add. Can you post your code snippet just to be sure?

from linfa.

Bastian1110 avatar Bastian1110 commented on July 30, 2024

Sure !
This is the code Im using to "export" a model using ciborium, this method has worked successfully with linfa-svm .

// In the winequality SVM example after "fiting" the SVM model

let model_value = cbor!(model).unwrap();
let mut vec_model = Vec::new();
let _cebor_writer = ciborium::ser::into_writer(&model_value, &mut vec_model);

//Esporting it to a .cbor file
let path: &Path = Path::new("./model.cbor");
fs::write(path, vec_model).unwrap();

Then, you can import the model and use it, like this :

//Reading the .cbor file and converting it to a ciborium value
let mut file = File::open("./model.cbor").unwrap();
let mut data: Vec<u8> = Vec::new();
file.read_to_end(&mut data).unwrap();
let model_value = ciborium::de::from_reader::<Value, _>(&data[..]).unwrap();

//Creating again the model, but its already trained 
let model: Svm<f64, bool> = model_value.deserialized().unwrap();
println!("{}", model);

This really works with ease (with the SVM-model), but the way I find out that a model doesn't support serde serialization is by trying to pass it to the cbor! macro, when a model does not support serialization, the following error appears:

the trait bound `<MODELNAME>: serde::ser::Serialize` is not satisfied
the following other types implement trait `serde::ser::Serialize`:
  &'a T
  &'a mut T
  ()
  (T0, T1)
  . . .

from linfa.

Bastian1110 avatar Bastian1110 commented on July 30, 2024

I just cloned your repository with the addition of serde support, thank you very much!
I tried to test it inside the extra-serde branch, my test was the same as described in the other comment, I tried to pass the CountVectorizer through the cbor! macro but I get the same error:

//In the countvectorization.rs example of linfa-preprocessing (inside the extra-serve branch)

let vectorizer_value = cbor!(vectorizer).unwrap();

But the following error occurs :

the trait bound `CountVectorizer: serde::ser::Serialize` is not satisfied
the following other types implement trait `serde::ser::Serialize`:
  &'a T
  &'a mut T
  ()
  (T0, T1)

Maybe Im testing it wrong? If so, any other idea on how to test it without merging to the master branch?

from linfa.

YuhanLiin avatar YuhanLiin commented on July 30, 2024

Did you enable the serde feature on the crate?

from linfa.

YuhanLiin avatar YuhanLiin commented on July 30, 2024

I just tested with the serde feature enabled and I asserted that CountVectorizer: Serialize holds. I'm going to merge the PR into master and you can test it from there.

from linfa.

Bastian1110 avatar Bastian1110 commented on July 30, 2024

I just tested adding the serde to the features in Cargo.toml and it works!
Thanks a lot!

from linfa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.