BabyFace
baby_face is a mix-in module to provide a simple classifier.
Installation
Add this line to your application's Gemfile:
gem 'baby_face'
And then execute:
$ bundle
Or install it yourself as:
$ gem install baby_face
Usage
target model( Poro, ActiveModel, ...)
class Jedi
include BabyFace
baby_face_for features: :name,
categories: [:light_side, :dark_side]
attr_accessor :name
def initialize(name)
@name = name
end
end
training
Jedi.new("Anakin Skywalker").baby_face.train_light_side
Jedi.new("Darth Maul").baby_face.train_dark_side
classify
Jedi.new("Luke Skywalker").baby_face.light_side? # => true
Jedi.new("Darth Vader").baby_face.dark_side? # => true
save training data
BabyFace.configuration.data_dir = "/tmp/baby_face"
Jedi.new("Luke Skywalker").baby_face.save # => /tmp/baby_face/jedi.babyface
more
tokenizer
default : String#split
baby_face_for features: :name,
categories: [:ham, :spam],
tokenizer: ->(text) {[text.upcase]}
nested object
support nested BabyFace object, array and hash.
class Entry < ActiveRecord::Base
has_many :comments
include BabyFace
baby_face_for features: [:title, :body, :comments],
categories: [:ham, :spam]
end
class Comment < ActiveRecord::Base
include BabyFace
baby_face_for features: [:title, :message]
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request