{"action":"created","comment":{"url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/comments/84682436","pull_request_review_id":5443779,"id":84682436,"diff_hunk":"@@ -49,19 +51,29 @@ def format_html_styles():\n     return template_env.get_template('styles.html').render()\n \n \n-def render_weighted_spans(weighted_spans_data):\n+def render_weighted_spans(weighted_spans_data, preserve_density=None):\n     \"\"\" Render text document with highlighted features.\n+    If preserve_density is True, then color for longer fragments will be\n+    less intensive than for shorter fragments, so that \"sum\" of intensities\n+    will correspond to feature weight.\n+    If preserve_density is None, then it's value is chosen depending on\n+    analyzer kind: it is preserved for \"char\" and \"char_wb\" analyzers,\n+    and not preserved for \"word\" analyzers.\n     \"\"\"\n+    if preserve_density is None:\n+        preserve_density = weighted_spans_data['analyzer'].startswith('char')\n     doc = weighted_spans_data['document']\n     weighted_spans = weighted_spans_data['weighted_spans']\n     char_weights = np.zeros(len(doc))\n     for _, spans, weight in weighted_spans:\n         for start, end in spans:\n+            if preserve_density:\n+                weight /= (end - start)\n             char_weights[start:end] += weight\n     # TODO - can be much smarter, join spans at least\n     # TODO - for longer documents, remove text without active features\n     not_found_weights = sorted(\n-        (feature, weight)\n+        (feature, weight / len(feature) if preserve_density else weight)","path":"eli5/formatters/html.py","position":55,"original_position":55,"commit_id":"be3d909b6449cfa649522de32726d674e05a8de5","original_commit_id":"be3d909b6449cfa649522de32726d674e05a8de5","user":{"login":"kmike","id":107893,"avatar_url":"https://avatars.githubusercontent.com/u/107893?v=3","gravatar_id":"","url":"https://api.github.com/users/kmike","html_url":"https://github.com/kmike","followers_url":"https://api.github.com/users/kmike/followers","following_url":"https://api.github.com/users/kmike/following{/other_user}","gists_url":"https://api.github.com/users/kmike/gists{/gist_id}","starred_url":"https://api.github.com/users/kmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmike/subscriptions","organizations_url":"https://api.github.com/users/kmike/orgs","repos_url":"https://api.github.com/users/kmike/repos","events_url":"https://api.github.com/users/kmike/events{/privacy}","received_events_url":"https://api.github.com/users/kmike/received_events","type":"User","site_admin":false},"body":"This part is tricky - non-text feature names can be lighter or darker depending on a length of their name; two features with equal weights can have different color if their names have different length. I don't know how to solve it :) My main motivation was to make highlighting compatible between char and token models, not so much between text and non-text features.\r\n\r\nMaybe it deserves its own solution - e.g. instead of showing non-text features inline before the text we may show them separated by new lines, and near each feature name show a rectangle, all rectangles of the same size. This way length of non-text feature name won't impact highlighting. To make it compatible with text rectangle may have a width similar to avg. word width (e.g. 5 chars).","created_at":"2016-10-24T13:06:57Z","updated_at":"2016-10-24T13:06:57Z","html_url":"https://github.com/TeamHG-Memex/eli5/pull/32#discussion_r84682436","pull_request_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/comments/84682436"},"html":{"href":"https://github.com/TeamHG-Memex/eli5/pull/32#discussion_r84682436"},"pull_request":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32","id":90407728,"html_url":"https://github.com/TeamHG-Memex/eli5/pull/32","diff_url":"https://github.com/TeamHG-Memex/eli5/pull/32.diff","patch_url":"https://github.com/TeamHG-Memex/eli5/pull/32.patch","issue_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/32","number":32,"state":"open","locked":false,"title":"Preserve density - see #30","user":{"login":"lopuhin","id":424613,"avatar_url":"https://avatars.githubusercontent.com/u/424613?v=3","gravatar_id":"","url":"https://api.github.com/users/lopuhin","html_url":"https://github.com/lopuhin","followers_url":"https://api.github.com/users/lopuhin/followers","following_url":"https://api.github.com/users/lopuhin/following{/other_user}","gists_url":"https://api.github.com/users/lopuhin/gists{/gist_id}","starred_url":"https://api.github.com/users/lopuhin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lopuhin/subscriptions","organizations_url":"https://api.github.com/users/lopuhin/orgs","repos_url":"https://api.github.com/users/lopuhin/repos","events_url":"https://api.github.com/users/lopuhin/events{/privacy}","received_events_url":"https://api.github.com/users/lopuhin/received_events","type":"User","site_admin":false},"body":"By default density is preserved (new behaviour) for char and char_wb analyzers, and old behaviour is kept for word analyzer, as discussed in #30.","created_at":"2016-10-21T15:47:52Z","updated_at":"2016-10-24T13:06:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c4465d86066727e291fdd4851ed7abb81978874d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32/commits","review_comments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32/comments","review_comment_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/32/comments","statuses_url":"https://api.github.com/repos/TeamHG-Memex/eli5/statuses/be3d909b6449cfa649522de32726d674e05a8de5","head":{"label":"TeamHG-Memex:preserve-density","ref":"preserve-density","sha":"be3d909b6449cfa649522de32726d674e05a8de5","user":{"login":"TeamHG-Memex","id":9270052,"avatar_url":"https://avatars.githubusercontent.com/u/9270052?v=3","gravatar_id":"","url":"https://api.github.com/users/TeamHG-Memex","html_url":"https://github.com/TeamHG-Memex","followers_url":"https://api.github.com/users/TeamHG-Memex/followers","following_url":"https://api.github.com/users/TeamHG-Memex/following{/other_user}","gists_url":"https://api.github.com/users/TeamHG-Memex/gists{/gist_id}","starred_url":"https://api.github.com/users/TeamHG-Memex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TeamHG-Memex/subscriptions","organizations_url":"https://api.github.com/users/TeamHG-Memex/orgs","repos_url":"https://api.github.com/users/TeamHG-Memex/repos","events_url":"https://api.github.com/users/TeamHG-Memex/events{/privacy}","received_events_url":"https://api.github.com/users/TeamHG-Memex/received_events","type":"Organization","site_admin":false},"repo":{"id":68256277,"name":"eli5","full_name":"TeamHG-Memex/eli5","owner":{"login":"TeamHG-Memex","id":9270052,"avatar_url":"https://avatars.githubusercontent.com/u/9270052?v=3","gravatar_id":"","url":"https://api.github.com/users/TeamHG-Memex","html_url":"https://github.com/TeamHG-Memex","followers_url":"https://api.github.com/users/TeamHG-Memex/followers","following_url":"https://api.github.com/users/TeamHG-Memex/following{/other_user}","gists_url":"https://api.github.com/users/TeamHG-Memex/gists{/gist_id}","starred_url":"https://api.github.com/users/TeamHG-Memex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TeamHG-Memex/subscriptions","organizations_url":"https://api.github.com/users/TeamHG-Memex/orgs","repos_url":"https://api.github.com/users/TeamHG-Memex/repos","events_url":"https://api.github.com/users/TeamHG-Memex/events{/privacy}","received_events_url":"https://api.github.com/users/TeamHG-Memex/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/TeamHG-Memex/eli5","description":"A library for debugging machine learning classifiers and explaining their predictions","fork":false,"url":"https://api.github.com/repos/TeamHG-Memex/eli5","forks_url":"https://api.github.com/repos/TeamHG-Memex/eli5/forks","keys_url":"https://api.github.com/repos/TeamHG-Memex/eli5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TeamHG-Memex/eli5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TeamHG-Memex/eli5/teams","hooks_url":"https://api.github.com/repos/TeamHG-Memex/eli5/hooks","issue_events_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/events{/number}","events_url":"https://api.github.com/repos/TeamHG-Memex/eli5/events","assignees_url":"https://api.github.com/repos/TeamHG-Memex/eli5/assignees{/user}","branches_url":"https://api.github.com/repos/TeamHG-Memex/eli5/branches{/branch}","tags_url":"https://api.github.com/repos/TeamHG-Memex/eli5/tags","blobs_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/refs{/sha}","trees_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TeamHG-Memex/eli5/statuses/{sha}","languages_url":"https://api.github.com/repos/TeamHG-Memex/eli5/languages","stargazers_url":"https://api.github.com/repos/TeamHG-Memex/eli5/stargazers","contributors_url":"https://api.github.com/repos/TeamHG-Memex/eli5/contributors","subscribers_url":"https://api.github.com/repos/TeamHG-Memex/eli5/subscribers","subscription_url":"https://api.github.com/repos/TeamHG-Memex/eli5/subscription","commits_url":"https://api.github.com/repos/TeamHG-Memex/eli5/commits{/sha}","git_commits_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/commits{/sha}","comments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/comments{/number}","issue_comment_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/comments{/number}","contents_url":"https://api.github.com/repos/TeamHG-Memex/eli5/contents/{+path}","compare_url":"https://api.github.com/repos/TeamHG-Memex/eli5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TeamHG-Memex/eli5/merges","archive_url":"https://api.github.com/repos/TeamHG-Memex/eli5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TeamHG-Memex/eli5/downloads","issues_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues{/number}","pulls_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls{/number}","milestones_url":"https://api.github.com/repos/TeamHG-Memex/eli5/milestones{/number}","notifications_url":"https://api.github.com/repos/TeamHG-Memex/eli5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TeamHG-Memex/eli5/labels{/name}","releases_url":"https://api.github.com/repos/TeamHG-Memex/eli5/releases{/id}","deployments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/deployments","created_at":"2016-09-15T01:04:57Z","updated_at":"2016-10-20T08:27:06Z","pushed_at":"2016-10-24T09:42:23Z","git_url":"git://github.com/TeamHG-Memex/eli5.git","ssh_url":"git@github.com:TeamHG-Memex/eli5.git","clone_url":"https://github.com/TeamHG-Memex/eli5.git","svn_url":"https://github.com/TeamHG-Memex/eli5","homepage":"","size":2000,"stargazers_count":7,"watchers_count":7,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":11,"forks":2,"open_issues":11,"watchers":7,"default_branch":"master"}},"base":{"label":"TeamHG-Memex:master","ref":"master","sha":"f0c67609a0ff080e21272b2c2e22a4040c187c3c","user":{"login":"TeamHG-Memex","id":9270052,"avatar_url":"https://avatars.githubusercontent.com/u/9270052?v=3","gravatar_id":"","url":"https://api.github.com/users/TeamHG-Memex","html_url":"https://github.com/TeamHG-Memex","followers_url":"https://api.github.com/users/TeamHG-Memex/followers","following_url":"https://api.github.com/users/TeamHG-Memex/following{/other_user}","gists_url":"https://api.github.com/users/TeamHG-Memex/gists{/gist_id}","starred_url":"https://api.github.com/users/TeamHG-Memex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TeamHG-Memex/subscriptions","organizations_url":"https://api.github.com/users/TeamHG-Memex/orgs","repos_url":"https://api.github.com/users/TeamHG-Memex/repos","events_url":"https://api.github.com/users/TeamHG-Memex/events{/privacy}","received_events_url":"https://api.github.com/users/TeamHG-Memex/received_events","type":"Organization","site_admin":false},"repo":{"id":68256277,"name":"eli5","full_name":"TeamHG-Memex/eli5","owner":{"login":"TeamHG-Memex","id":9270052,"avatar_url":"https://avatars.githubusercontent.com/u/9270052?v=3","gravatar_id":"","url":"https://api.github.com/users/TeamHG-Memex","html_url":"https://github.com/TeamHG-Memex","followers_url":"https://api.github.com/users/TeamHG-Memex/followers","following_url":"https://api.github.com/users/TeamHG-Memex/following{/other_user}","gists_url":"https://api.github.com/users/TeamHG-Memex/gists{/gist_id}","starred_url":"https://api.github.com/users/TeamHG-Memex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TeamHG-Memex/subscriptions","organizations_url":"https://api.github.com/users/TeamHG-Memex/orgs","repos_url":"https://api.github.com/users/TeamHG-Memex/repos","events_url":"https://api.github.com/users/TeamHG-Memex/events{/privacy}","received_events_url":"https://api.github.com/users/TeamHG-Memex/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/TeamHG-Memex/eli5","description":"A library for debugging machine learning classifiers and explaining their predictions","fork":false,"url":"https://api.github.com/repos/TeamHG-Memex/eli5","forks_url":"https://api.github.com/repos/TeamHG-Memex/eli5/forks","keys_url":"https://api.github.com/repos/TeamHG-Memex/eli5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TeamHG-Memex/eli5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TeamHG-Memex/eli5/teams","hooks_url":"https://api.github.com/repos/TeamHG-Memex/eli5/hooks","issue_events_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/events{/number}","events_url":"https://api.github.com/repos/TeamHG-Memex/eli5/events","assignees_url":"https://api.github.com/repos/TeamHG-Memex/eli5/assignees{/user}","branches_url":"https://api.github.com/repos/TeamHG-Memex/eli5/branches{/branch}","tags_url":"https://api.github.com/repos/TeamHG-Memex/eli5/tags","blobs_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/refs{/sha}","trees_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TeamHG-Memex/eli5/statuses/{sha}","languages_url":"https://api.github.com/repos/TeamHG-Memex/eli5/languages","stargazers_url":"https://api.github.com/repos/TeamHG-Memex/eli5/stargazers","contributors_url":"https://api.github.com/repos/TeamHG-Memex/eli5/contributors","subscribers_url":"https://api.github.com/repos/TeamHG-Memex/eli5/subscribers","subscription_url":"https://api.github.com/repos/TeamHG-Memex/eli5/subscription","commits_url":"https://api.github.com/repos/TeamHG-Memex/eli5/commits{/sha}","git_commits_url":"https://api.github.com/repos/TeamHG-Memex/eli5/git/commits{/sha}","comments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/comments{/number}","issue_comment_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/comments{/number}","contents_url":"https://api.github.com/repos/TeamHG-Memex/eli5/contents/{+path}","compare_url":"https://api.github.com/repos/TeamHG-Memex/eli5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TeamHG-Memex/eli5/merges","archive_url":"https://api.github.com/repos/TeamHG-Memex/eli5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TeamHG-Memex/eli5/downloads","issues_url":"https://api.github.com/repos/TeamHG-Memex/eli5/issues{/number}","pulls_url":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls{/number}","milestones_url":"https://api.github.com/repos/TeamHG-Memex/eli5/milestones{/number}","notifications_url":"https://api.github.com/repos/TeamHG-Memex/eli5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TeamHG-Memex/eli5/labels{/name}","releases_url":"https://api.github.com/repos/TeamHG-Memex/eli5/releases{/id}","deployments_url":"https://api.github.com/repos/TeamHG-Memex/eli5/deployments","created_at":"2016-09-15T01:04:57Z","updated_at":"2016-10-20T08:27:06Z","pushed_at":"2016-10-24T09:42:23Z","git_url":"git://github.com/TeamHG-Memex/eli5.git","ssh_url":"git@github.com:TeamHG-Memex/eli5.git","clone_url":"https://github.com/TeamHG-Memex/eli5.git","svn_url":"https://github.com/TeamHG-Memex/eli5","homepage":"","size":2000,"stargazers_count":7,"watchers_count":7,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":11,"forks":2,"open_issues":11,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32"},"html":{"href":"https://github.com/TeamHG-Memex/eli5/pull/32"},"issue":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/32"},"comments":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/TeamHG-Memex/eli5/statuses/be3d909b6449cfa649522de32726d674e05a8de5"}}}}
{"actor":{"display_login":"kmike"}}