Project

baby_face

0.01
No commit activity in last 3 years
No release in over 3 years
baby_face is a mix-in module to provide a simple classifier.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

 Project Readme

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request