Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new field for names prediction #247

Merged
merged 4 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bothub/api/v1/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Meta:
'language',
'algorithm',
'use_competing_intents',
'use_name_entities',
'categories',
'description',
'is_private',
Expand Down Expand Up @@ -67,6 +68,7 @@ class Meta:
'algorithm',
'use_language_model_featurizer',
'use_competing_intents',
'use_name_entities',
'categories',
'categories_list',
'description',
Expand Down
1 change: 1 addition & 0 deletions bothub/api/v2/repository/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Meta:
'algorithm',
'use_language_model_featurizer',
'use_competing_intents',
'use_name_entities',
]
read_only = [
'uuid',
Expand Down
1 change: 1 addition & 0 deletions bothub/common/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RepositoryUpdateInline(admin.TabularInline):
'language',
'algorithm',
'use_competing_intents',
'use_name_entities',
'created_at',
'by',
'training_started_at',
Expand Down
23 changes: 23 additions & 0 deletions bothub/common/migrations/0030_auto_20190327_2003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.1.5 on 2019-03-27 20:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0029_auto_20190126_0247'),
]

operations = [
migrations.AddField(
model_name='repository',
name='use_name_entities',
field=models.BooleanField(default=False, help_text='When enabling name entities you will receive name of people, companies and places as results of your predictions.', verbose_name='Use name entities'),
),
migrations.AddField(
model_name='repositoryupdate',
name='use_name_entities',
field=models.BooleanField(default=False),
),
]
12 changes: 12 additions & 0 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class Meta:
help_text=_('When using competing intents the confidence of the ' +
'prediction is distributed in all the intents.'),
default=False)
use_name_entities = models.BooleanField(
_('Use name entities'),
help_text=_('When enabling name entities you will receive name of ' +
'people, companies and places as results of your ' +
'predictions.'),
default=False)
categories = models.ManyToManyField(
RepositoryCategory,
help_text=CATEGORIES_HELP_TEXT)
Expand Down Expand Up @@ -418,6 +424,7 @@ class Meta:
default=Repository.ALGORITHM_STATISTICAL_MODEL,
)
use_competing_intents = models.BooleanField(default=False)
use_name_entities = models.BooleanField(default=False)
created_at = models.DateTimeField(
_('created at'),
auto_now_add=True)
Expand Down Expand Up @@ -525,6 +532,9 @@ def ready_for_train(self):
if previous_update.use_competing_intents is not \
self.repository.use_competing_intents:
return True
if previous_update.use_name_entities is not \
self.repository.use_name_entities:
return True
if previous_update.failed_at:
return True

Expand Down Expand Up @@ -574,12 +584,14 @@ def start_training(self, by):
self.training_started_at = timezone.now()
self.algorithm = self.repository.algorithm
self.use_competing_intents = self.repository.use_competing_intents
self.use_name_entities = self.repository.use_name_entities
self.save(
update_fields=[
'by',
'training_started_at',
'algorithm',
'use_competing_intents',
'use_name_entities',
])

def save_training(self, bot_data):
Expand Down
44 changes: 44 additions & 0 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,50 @@ def test_equal_repository_value_after_train(self):
self.assertFalse(current_update.use_competing_intents)


class UseNameEntitiesTestCase(TestCase):
def setUp(self):
self.language = languages.LANGUAGE_EN

self.owner = User.objects.create_user('owner@user.com', 'user')

self.repository = Repository.objects.create(
owner=self.owner,
name='Test',
slug='test',
language=self.language,
use_name_entities=True)

RepositoryExample.objects.create(
repository_update=self.repository.current_update(),
text='my name is Douglas',
intent='greet')
RepositoryExample.objects.create(
repository_update=self.repository.current_update(),
text='my name is John',
intent='greet')

def test_change_ready_for_train(self):
self.assertTrue(self.repository.ready_for_train)
current_update = self.repository.current_update()
current_update.start_training(self.owner)
current_update.save_training(b'')
self.assertFalse(self.repository.ready_for_train)
self.repository.use_name_entities = False
self.repository.save()
self.assertTrue(self.repository.ready_for_train)
self.repository.use_name_entities = True
self.repository.save()
self.assertFalse(self.repository.ready_for_train)

def test_equal_repository_value_after_train(self):
current_update = self.repository.current_update()
self.repository.use_name_entities = False
self.repository.save()
current_update.start_training(self.owner)
current_update.save_training(b'')
self.assertFalse(current_update.use_name_entities)


class RepositoryUpdateWarnings(TestCase):
def setUp(self):
self.language = languages.LANGUAGE_EN
Expand Down