diarize-ruby 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81c40e31baa740bf18b34d2de82bab3ae7897461
4
- data.tar.gz: 3e987f962651badd8fc8a79d73a718d4660fe532
3
+ metadata.gz: 6538efc1cab1c18e656dcc50c1e2b57d8f9f38a7
4
+ data.tar.gz: d86715c3e757994d859c9847e013c5501895a5f1
5
5
  SHA512:
6
- metadata.gz: c96801c0aa7dbf3409853fd519c18ce68ee291cb294f509ec642059152ac0d8cfc81936afe1b4c21d3ff4440b83e37c09594e36dddbe521e251697715653839f
7
- data.tar.gz: a554a9ffc2de0f8f48aa198b7e11d3db639c49efbd941cad920f10453dc2c875ddd776a24c98685a14a3cac24f5890944efb947e1c143c1a8c81e63fada33587
6
+ metadata.gz: 0762b0b955406e9c43b95e44331f518379c90a3403addcb8478bdae93746095ed060805f4e128bfd3a7640118ba821b506e467d99b3dfe3679922056eeaafac4
7
+ data.tar.gz: 0a38dcab217b7b45595d734434be3ffbdf9755c7d869bb93a49198b288b45b59d2dcdb078213d2626fc67d70bb7d955b0eeaf5982a7cb3482ea647aa9af5328d
@@ -159,8 +159,7 @@ module Diarize
159
159
  'ws:gender' => gender,
160
160
  'ws:model' => model_uri,
161
161
  'ws:mean_log_likelihood' => mean_log_likelihood,
162
- 'ws:supervector_hash' => supervector.hash.to_s,
163
- 'ws:sha' => supervector.sha
162
+ 'ws:supervector_hash' => supervector.hash.to_s
164
163
  }
165
164
  end
166
165
 
@@ -169,8 +168,7 @@ module Diarize
169
168
  'gender' => gender,
170
169
  'model' => model_uri,
171
170
  'mean_log_likelihood' => mean_log_likelihood,
172
- 'supervector_hash' => supervector.hash.to_s,
173
- 'sha' => supervector.sha
171
+ 'supervector_hash' => supervector.hash.to_s
174
172
  }
175
173
  end
176
174
 
@@ -3,65 +3,66 @@ module Diarize
3
3
  attr_reader :vector
4
4
 
5
5
  def initialize(vector)
6
- @vector = vector
6
+ @vector = vector.is_a?(Array) ? Vector.elements(vector) : vector
7
7
  end
8
8
 
9
- def self.generate_from_model(model)
10
- # Generates a supervector from a LIUM GMM
11
- dim = model.nb_of_components * model.components.get(0).dim
12
- # vector = DoubleMatrix.new(1, dim)
13
- # vector = Vector.elements(Array.new(dim, 0))
14
- vector = Array.new(dim, 0)
15
- model.nb_of_components.times do |k|
16
- gaussian = model.components.get(k)
17
- gaussian.dim.times do |i|
18
- vector[k * gaussian.dim + i] = gaussian.mean(i)
9
+ class << self
10
+
11
+ def generate_from_model(model)
12
+ # Generates a supervector from a LIUM GMM
13
+ dim = model.nb_of_components * model.components.get(0).dim
14
+ vector = Array.new(dim, 0)
15
+ model.nb_of_components.times do |k|
16
+ gaussian = model.components.get(k)
17
+ gaussian.dim.times do |i|
18
+ vector[k * gaussian.dim + i] = gaussian.mean(i)
19
+ end
19
20
  end
21
+ SuperVector.new(Vector.elements(vector))
20
22
  end
21
- # SuperVector.new(vector)
22
- SuperVector.new(Vector.elements(vector))
23
- end
24
23
 
25
- def self.ubm_gaussian_weights
26
- # Returns a vector of gaussian weights, same dimension as speaker's super vectors
27
- @@ubm_gaussian_weights ||= begin
28
- ubm = Speaker.ubm
29
- # weights = DoubleMatrix.new(1, ubm.supervector.dim)
30
- weights = Array.new(ubm.supervector.dim, 0)
31
- ubm.model.nb_of_components.times do |k|
32
- gaussian = ubm.model.components.get(k)
33
- gaussian.dim.times do |i|
34
- weights[k * gaussian.dim + i] = gaussian.weight
24
+ def ubm_gaussian_weights
25
+ # Returns a vector of gaussian weights, same dimension as speaker's super vectors
26
+ @@ubm_gaussian_weights ||= begin
27
+ ubm = Speaker.ubm
28
+ # weights = DoubleMatrix.new(1, ubm.supervector.dim)
29
+ weights = Array.new(ubm.supervector.dim, 0)
30
+ ubm.model.nb_of_components.times do |k|
31
+ gaussian = ubm.model.components.get(k)
32
+ gaussian.dim.times do |i|
33
+ weights[k * gaussian.dim + i] = gaussian.weight
34
+ end
35
35
  end
36
+ Vector.elements(weights)
36
37
  end
37
- Vector.elements(weights)
38
38
  end
39
- end
40
39
 
41
- def self.ubm_covariance
42
- # Returns a vector of diagonal covariances, same dimension as speaker's super vectors
43
- @@ubm_covariance ||= begin
44
- ubm = Speaker.ubm
45
- # cov = DoubleMatrix.new(1, ubm.supervector.dim)
46
- cov = Array.new(ubm.supervector.dim)
47
- ubm.model.nb_of_components.times do |k|
48
- gaussian = ubm.model.components.get(k)
49
- gaussian.dim.times do |i|
50
- cov[k * gaussian.dim + i] = gaussian.getCovariance(i, i)
40
+ def ubm_covariance
41
+ # Returns a vector of diagonal covariances, same dimension as speaker's super vectors
42
+ @@ubm_covariance ||= begin
43
+ ubm = Speaker.ubm
44
+ # cov = DoubleMatrix.new(1, ubm.supervector.dim)
45
+ cov = Array.new(ubm.supervector.dim)
46
+ ubm.model.nb_of_components.times do |k|
47
+ gaussian = ubm.model.components.get(k)
48
+ gaussian.dim.times do |i|
49
+ cov[k * gaussian.dim + i] = gaussian.getCovariance(i, i)
50
+ end
51
51
  end
52
+ Vector.elements(cov)
52
53
  end
53
- Vector.elements(cov)
54
54
  end
55
- end
56
55
 
57
- def self.divergence(sv1, sv2)
58
- # ubm_gaussian_weights.mul(((sv1.vector - sv2.vector) ** 2) / ubm_covariance).sum
59
- diff = sv1.vector - sv2.vector
60
- square = diff.map {|el| el ** 2}
61
- codiv = Vector.elements(square.each.with_index.inject([]) {|a,(el,ix)| a << el / ubm_covariance[ix]})
62
- mult = ubm_gaussian_weights.each.with_index.inject([]) {|a,(el,ix)| a << el * codiv[ix]}
63
- mult.inject(0, :+)
64
- end
56
+ def divergence(sv1, sv2)
57
+ # ubm_gaussian_weights.mul(((sv1.vector - sv2.vector) ** 2) / ubm_covariance).sum
58
+ diff = sv1.vector - sv2.vector
59
+ square = diff.map {|el| el ** 2}
60
+ codiv = Vector.elements(square.each.with_index.inject([]) {|a,(el,ix)| a << el / ubm_covariance[ix]})
61
+ mult = ubm_gaussian_weights.each.with_index.inject([]) {|a,(el,ix)| a << el * codiv[ix]}
62
+ mult.inject(0, :+)
63
+ end
64
+
65
+ end # class
65
66
 
66
67
  def dim
67
68
  @vector.size
@@ -71,10 +72,6 @@ module Diarize
71
72
  @vector.hash
72
73
  end
73
74
 
74
- def sha
75
- Digest::SHA256.hexdigest(hash.to_s)
76
- end
77
-
78
75
  def to_a
79
76
  @vector.to_a
80
77
  end
@@ -1,3 +1,3 @@
1
1
  module Diarize
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
@@ -106,7 +106,6 @@ class SpeakerTest < Test::Unit::TestCase
106
106
  assert_equal true, to_rdf.include?("ws:model")
107
107
  assert_equal true, to_rdf.include?("ws:mean_log_likelihood")
108
108
  assert_equal true, to_rdf.include?("ws:supervector_hash")
109
- assert_equal true, to_rdf.include?("ws:sha")
110
109
  assert_equal true, to_rdf.include?("https://www.example.com/model/1")
111
110
  end
112
111
 
@@ -118,7 +117,6 @@ class SpeakerTest < Test::Unit::TestCase
118
117
  assert_equal true, as_json.has_key?('model')
119
118
  assert_equal true, as_json.has_key?('mean_log_likelihood')
120
119
  assert_equal true, as_json.has_key?('supervector_hash')
121
- assert_equal true, as_json.has_key?('sha')
122
120
  end
123
121
 
124
122
  def test_to_json
@@ -130,6 +128,5 @@ class SpeakerTest < Test::Unit::TestCase
130
128
  assert_equal true, as_json.has_key?('model')
131
129
  assert_equal true, as_json.has_key?('mean_log_likelihood')
132
130
  assert_equal true, as_json.has_key?('supervector_hash')
133
- assert_equal true, as_json.has_key?('sha')
134
131
  end
135
132
  end
@@ -15,16 +15,24 @@ class SuperVectorTest < Test::Unit::TestCase
15
15
  end
16
16
  end
17
17
 
18
- def test_hash
18
+ def test_initialize_from_supervector
19
19
  model = Diarize::Speaker.load_model(File.join(File.dirname(__FILE__), 'data', 'speaker1.gmm'))
20
- sv = Diarize::SuperVector.generate_from_model(model)
21
- assert_equal sv.vector.hash, sv.hash
20
+ sv1 = Diarize::SuperVector.generate_from_model(model)
21
+ sv2 = Diarize::SuperVector.new(sv1)
22
+ assert_equal sv1.hash, sv2.hash
23
+ end
24
+
25
+ def test_initialize_from_array
26
+ model = Diarize::Speaker.load_model(File.join(File.dirname(__FILE__), 'data', 'speaker1.gmm'))
27
+ sv1 = Diarize::SuperVector.generate_from_model(model)
28
+ sv2 = Diarize::SuperVector.new(sv1.to_a)
29
+ assert_equal sv1.hash, sv2.hash
22
30
  end
23
31
 
24
- def test_sha
32
+ def test_hash
25
33
  model = Diarize::Speaker.load_model(File.join(File.dirname(__FILE__), 'data', 'speaker1.gmm'))
26
34
  sv = Diarize::SuperVector.generate_from_model(model)
27
- assert_equal Digest::SHA256.hexdigest(sv.hash.to_s), sv.sha
35
+ assert_equal sv.vector.hash, sv.hash
28
36
  end
29
37
 
30
38
  def test_to_a
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class VersionTest < Test::Unit::TestCase
4
4
 
5
5
  def test_current_version
6
- assert_equal "0.3.9", Diarize::VERSION
6
+ assert_equal "0.3.10", Diarize::VERSION
7
7
  end
8
8
 
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diarize-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Raimond