├── LICENSE ├── general-data-science └── similarities-measures │ ├── poetry.lock │ ├── pyproject.toml │ ├── similarity-measures.ipynb │ └── similaritymeasures.png ├── natural-language-processing ├── embedding-models │ ├── data │ │ └── training_data.csv │ ├── domain_adaption_fine_tune_nlp_model.ipynb │ ├── logs │ │ └── fit │ │ │ └── 20230630-152712 │ │ │ ├── train │ │ │ └── events.out.tfevents.1688153232.Shashanks-MacBook-Pro-2.local.44453.0.v2 │ │ │ └── validation │ │ │ └── events.out.tfevents.1688153249.Shashanks-MacBook-Pro-2.local.44453.1.v2 │ ├── packages │ │ └── tensorflow_text-2.10.0-cp39-cp39-macosx_11_0_arm64.whl │ ├── poetry.lock │ ├── pyproject.toml │ └── utils.py ├── text-processing │ ├── Building Blocks Text Pre-Processing.ipynb │ ├── poetry.lock │ └── pyproject.toml ├── topic-modeling │ ├── Evaluate Topic Models.ipynb │ ├── Introduction to Topic Modeling.ipynb │ ├── data │ │ └── NIPS Papers.zip │ ├── poetry.lock │ ├── pyproject.toml │ └── results │ │ ├── lda_tuning_results.csv │ │ ├── ldavis_prepared_10 │ │ ├── ldavis_prepared_10.html │ │ ├── ldavis_tuned_8 │ │ └── ldavis_tuned_8.html └── transformers-series │ ├── poetry.lock │ ├── pyproject.toml │ └── sentiment_analysis_bert.ipynb └── recommender ├── published_notebooks └── recommendation_python_lightfm.ipynb └── results ├── profiler_books_metadata_1.html ├── profiler_books_metadata_2.html └── profiler_interactions.html /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /general-data-science/similarities-measures/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "similarities-measures" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Shashank Kapadia "] 6 | readme = "README.md" 7 | packages = [{include = "similarities_measures"}] 8 | 9 | [tool.poetry.dependencies] 10 | python = ">=3.9,<3.10" 11 | jupyterlab = "^3.5.2" 12 | scikit-learn = "^1.2.0" 13 | matplotlib = "^3.6.2" 14 | seaborn = "^0.12.1" 15 | 16 | 17 | [build-system] 18 | requires = ["poetry-core"] 19 | build-backend = "poetry.core.masonry.api" 20 | -------------------------------------------------------------------------------- /general-data-science/similarities-measures/similarity-measures.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1d654a7e-fe50-495a-9235-303b16100d51", 6 | "metadata": {}, 7 | "source": [ 8 | "## Comparing 5 Data Similarity Measures\n", 9 | "##### Understanding Similarity Measures in Data Analysis and Machine Learning: A Comprehensive Guide\n", 10 | "** **\n", 11 | "*Preface: This article presents a summary of information about the given topic. It should not be considered original research. The information and code included in this article have may be influenced by things I have read or seen in the past from various online articles, research papers, books, and open-source code.*\n", 12 | "\n", 13 | "#### Introduction\n", 14 | "Similarity measures are a vital tool in many data analysis and machine learning tasks, allowing us to compare and evaluate the similarity between different pieces of data. Many different measures are available, each with pros and cons and suitable for different data types and tasks. \n", 15 | "\n", 16 | "This article will explore some of the most common similarity measures and compare their strengths and weaknesses. By understanding the characteristics and limitations of these measures, we can choose the most appropriate one for our specific needs and ensure the accuracy and relevance of our results.\n", 17 | "\n", 18 | "** **\n", 19 | "1. #### Euclidean Distance\n", 20 | "\n", 21 | "This measure calculates the straight-line distance between two points in n-dimensional space. It is often used for continuous numerical data and is easy to understand and implement. However, it can be sensitive to outliers and does not account for the relative importance of different features." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "id": "662570b5-f57b-426f-9e4e-7c7ed13ee897", 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "from scipy.spatial import distance\n", 32 | "\n", 33 | "# Calculate Euclidean distance between two points\n", 34 | "point1 = [1, 2, 3]\n", 35 | "point2 = [4, 5, 6]\n", 36 | "\n", 37 | "# Use the euclidean function from scipy's distance module to calculate the Euclidean distance\n", 38 | "euclidean_distance = distance.euclidean(point1, point2)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "id": "251a9a8b-1399-43b6-8d5d-312eaa9d87c1", 44 | "metadata": {}, 45 | "source": [ 46 | "#### Manhattan Distance\n", 47 | "\n", 48 | "This measure calculates the distance between two points by considering the absolute differences of their coordinates in each dimension and summing them. It is less sensitive to outliers than Euclidean distance, but it may not accurately reflect the actual distance between points in some cases." 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "id": "9a535f95-56a2-4960-880f-dc5d8c003949", 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "from scipy.spatial import distance\n", 59 | "\n", 60 | "# Calculate Manhattan distance between two points\n", 61 | "point1 = [1, 2, 3]\n", 62 | "point2 = [4, 5, 6]\n", 63 | "\n", 64 | "# Use the cityblock function from scipy's distance module to calculate the Manhattan distance\n", 65 | "manhattan_distance = distance.cityblock(point1, point2)\n", 66 | "\n", 67 | "# Print the result\n", 68 | "print(\"Manhattan Distance between the given two points: \" + \\\n", 69 | " str(manhattan_distance))" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "id": "20eee091-e3f0-4b67-87e6-165d5c36f0dd", 75 | "metadata": {}, 76 | "source": [ 77 | "#### Cosine Similarity\n", 78 | "\n", 79 | "This measure calculates the similarity between two vectors by considering their angle. It is often used for text data and is resistant to changes in the magnitude of the vectors. However, it does not consider the relative importance of different features." 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "id": "fb9fa0b3-86a1-4079-99f7-33891f93f0b6", 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "from sklearn.metrics.pairwise import cosine_similarity\n", 90 | "\n", 91 | "# Calculate cosine similarity between two vectors\n", 92 | "vector1 = [1, 2, 3]\n", 93 | "vector2 = [4, 5, 6]\n", 94 | "\n", 95 | "# Use the cosine_similarity function from scikit-learn to calculate the similarity\n", 96 | "cosine_sim = cosine_similarity([vector1], [vector2])[0][0]\n", 97 | "\n", 98 | "# Print the result\n", 99 | "print(\"Cosine Similarity between the given two vectors: \" + \\\n", 100 | " str(cosine_sim))" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "id": "22288d67-7006-4025-9185-491f3100dfe0", 106 | "metadata": {}, 107 | "source": [ 108 | "#### Jaccard Similarity\n", 109 | "\n", 110 | "This measure calculates the similarity between two sets by considering the size of their intersection and union. It is often used for categorical data and is resistant to changes in the size of the sets. However, it does not consider the sets' order or frequency of elements." 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "id": "3d3339eb-60cb-4bab-8ca4-3ffc40ead500", 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "def jaccard_similarity(list1, list2):\n", 121 | " \"\"\"\n", 122 | " Calculates the Jaccard similarity between two lists.\n", 123 | " \n", 124 | " Parameters:\n", 125 | " list1 (list): The first list to compare.\n", 126 | " list2 (list): The second list to compare.\n", 127 | " \n", 128 | " Returns:\n", 129 | " float: The Jaccard similarity between the two lists.\n", 130 | " \"\"\"\n", 131 | " # Convert the lists to sets for easier comparison\n", 132 | " s1 = set(list1)\n", 133 | " s2 = set(list2)\n", 134 | " \n", 135 | " # Calculate the Jaccard similarity by taking the length of the intersection of the sets\n", 136 | " # and dividing it by the length of the union of the sets\n", 137 | " return float(len(s1.intersection(s2)) / len(s1.union(s2)))\n", 138 | "\n", 139 | "# Calculate Jaccard similarity between two sets\n", 140 | "set1 = [1, 2, 3]\n", 141 | "set2 = [2, 3, 4]\n", 142 | "jaccard_sim = jaccard_similarity(set1, set2)\n", 143 | "\n", 144 | "# Print the result\n", 145 | "print(\"Jaccard Similarity between the given two sets: \" + \\\n", 146 | " str(jaccard_sim))\n" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "id": "1c0bff22-35f0-4a3f-bb1b-dab41fa87843", 152 | "metadata": {}, 153 | "source": [ 154 | "#### Pearson Correlation Coefficient\n", 155 | "\n", 156 | "This measure calculates the linear correlation between two variables. It is often used for continuous numerical data and considers the relative importance of different features. However, it may not accurately reflect non-linear relationships." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "id": "66c09410-c3fd-46cb-bcc6-8adf715105b7", 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "import numpy as np\n", 167 | "\n", 168 | "# Calculate Pearson correlation coefficient between two variables\n", 169 | "x = [1, 2, 3, 4]\n", 170 | "y = [2, 3, 4, 5]\n", 171 | "\n", 172 | "# Numpy corrcoef function to calculate the Pearson correlation coefficient and p-value\n", 173 | "pearson_corr = np.corrcoef(x, y)[0][1]\n", 174 | "\n", 175 | "# Print the result\n", 176 | "print(\"Pearson Correlation between the given two variables: \" + \\\n", 177 | " str(pearson_corr))" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "id": "7a5e24a8-b8cc-41fc-a582-b5134d55f07b", 183 | "metadata": {}, 184 | "source": [ 185 | "** **\n", 186 | "### Practical Scenario\n", 187 | "\n", 188 | "Suppose we have 5 items with numerical attributes and we want to compare the similarities between these products in order to facilitate applications such as clustering, classification, or perhaps, recommendations." 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "id": "bdec85a6-0f50-413d-857a-6b90c5bb8b04", 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "import numpy as np\n", 199 | "import seaborn as sns\n", 200 | "import random\n", 201 | "import matplotlib.pyplot as plt\n", 202 | "import pprint\n", 203 | "\n", 204 | "def calculate_similarities(products):\n", 205 | " \"\"\"Calculate the similarity measures between all pairs of products.\n", 206 | " \n", 207 | " Parameters\n", 208 | " ----------\n", 209 | " products : list\n", 210 | " A list of dictionaries containing the attributes of the products.\n", 211 | " \n", 212 | " Returns\n", 213 | " -------\n", 214 | " euclidean_similarities : numpy array\n", 215 | " An array containing the Euclidean distance between each pair of products.\n", 216 | " manhattan_distances : numpy array\n", 217 | " An array containing the Manhattan distance between each pair of products.\n", 218 | " cosine_similarities : numpy array\n", 219 | " An array containing the cosine similarity between each pair of products.\n", 220 | " jaccard_similarities : numpy array\n", 221 | " An array containing the Jaccard index between each pair of products.\n", 222 | " pearson_similarities : numpy array\n", 223 | " An array containing the Pearson correlation coefficient between each pair of products.\n", 224 | " \"\"\"\n", 225 | " # Initialize arrays to store the similarity measures\n", 226 | " euclidean_similarities = np.zeros((len(products), len(products)))\n", 227 | " manhattan_distances = np.zeros((len(products), len(products)))\n", 228 | " cosine_similarities = np.zeros((len(products), len(products)))\n", 229 | " jaccard_similarities = np.zeros((len(products), len(products)))\n", 230 | " pearson_similarities = np.zeros((len(products), len(products)))\n", 231 | "\n", 232 | " # Calculate all the similarity measures in a single loop\n", 233 | " for i in range(len(products)):\n", 234 | " for j in range(i+1, len(products)):\n", 235 | " p1 = products[i]['attributes']\n", 236 | " p2 = products[j]['attributes']\n", 237 | "\n", 238 | " # Calculate Euclidean distance\n", 239 | " euclidean_similarities[i][j] = distance.euclidean(p1, p2)\n", 240 | " euclidean_similarities[j][i] = euclidean_similarities[i][j]\n", 241 | "\n", 242 | " # Calculate Manhattan distance\n", 243 | " manhattan_distances[i][j] = distance.cityblock(p1, p2)\n", 244 | " manhattan_distances[j][i] = manhattan_distances[i][j]\n", 245 | "\n", 246 | " # Calculate cosine similarity\n", 247 | " cosine_similarities[i][j] = cosine_similarity([p1], [p2])[0][0]\n", 248 | " cosine_similarities[j][i] = cosine_similarities[i][j]\n", 249 | "\n", 250 | " # Calculate Jaccard index\n", 251 | " jaccard_similarities[i][j] = jaccard_similarity(p1, p2)\n", 252 | " jaccard_similarities[j][i] = jaccard_similarities[i][j]\n", 253 | "\n", 254 | " # Calculate Pearson correlation coefficient\n", 255 | " pearson_similarities[i][j] = np.corrcoef(p1, p2)[0][1]\n", 256 | " pearson_similarities[j][i] = pearson_similarities[i][j]\n", 257 | " \n", 258 | " return euclidean_similarities, manhattan_distances, cosine_similarities, jaccard_similarities, pearson_similarities\n", 259 | "\n", 260 | "def plot_similarities(similarities_list, labels, titles):\n", 261 | " \"\"\"Plot the given similarities as heatmaps in subplots.\n", 262 | " \n", 263 | " Parameters\n", 264 | " ----------\n", 265 | " similarities_list : list of numpy arrays\n", 266 | " A list of arrays containing the similarities between the products.\n", 267 | " labels : list\n", 268 | " A list of strings containing the labels for the products.\n", 269 | " titles : list\n", 270 | " A list of strings containing the titles for each plot.\n", 271 | " \n", 272 | " Returns\n", 273 | " -------\n", 274 | " None\n", 275 | " This function does not return any values. It only plots the heatmaps.\n", 276 | " \"\"\"\n", 277 | " # Set up the plot\n", 278 | " fig, ax = plt.subplots(nrows=1, \n", 279 | " ncols=len(similarities_list), figsize=(6*len(similarities_list), 6/1.680))\n", 280 | "\n", 281 | " for i, similarities in enumerate(similarities_list):\n", 282 | " # Plot the heatmap\n", 283 | " sns.heatmap(similarities, xticklabels=labels, yticklabels=labels, ax=ax[i])\n", 284 | " ax[i].set_title(titles[i])\n", 285 | " ax[i].set_xlabel(\"Product\")\n", 286 | " ax[i].set_ylabel(\"Product\")\n", 287 | " \n", 288 | " # Show the plot\n", 289 | " plt.show()" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": null, 295 | "id": "17961dbd-b85d-4ce1-889d-fb5e2d118080", 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [ 299 | "# Define the products and their attributes\n", 300 | "products = [\n", 301 | " {'name': 'Product 1', 'attributes': random.sample(range(1, 11), 5)},\n", 302 | " {'name': 'Product 2', 'attributes': random.sample(range(1, 11), 5)},\n", 303 | " {'name': 'Product 3', 'attributes': random.sample(range(1, 11), 5)},\n", 304 | " {'name': 'Product 4', 'attributes': random.sample(range(1, 11), 5)},\n", 305 | " {'name': 'Product 5', 'attributes': random.sample(range(1, 11), 5)}\n", 306 | "]\n", 307 | "\n", 308 | "pprint.pprint(products)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": null, 314 | "id": "9bafc61f-f777-447d-a422-f8ac5bdf2079", 315 | "metadata": {}, 316 | "outputs": [], 317 | "source": [ 318 | "euclidean_similarities, manhattan_distances, \\\n", 319 | "cosine_similarities, jaccard_similarities, \\\n", 320 | "pearson_similarities = calculate_similarities(products)\n", 321 | "\n", 322 | "# Set the labels for the x-axis and y-axis\n", 323 | "product_labels = [product['name'] for product in products]\n", 324 | "\n", 325 | "# List of similarity measures and their titles\n", 326 | "similarities_list = [euclidean_similarities, cosine_similarities, pearson_similarities, \n", 327 | " jaccard_similarities, manhattan_distances]\n", 328 | "titles = [\"Euclidean Distance\", \"Cosine Similarity\", \"Pearson Correlation Coefficient\", \n", 329 | " \"Jaccard Index\", \"Manhattan Distance\"]\n", 330 | "\n", 331 | "# Plot the heatmaps\n", 332 | "plot_similarities(similarities_list, product_labels, titles)" 333 | ] 334 | }, 335 | { 336 | "cell_type": "markdown", 337 | "id": "9a507819-e4f2-4b28-b1f4-fd215cfff40d", 338 | "metadata": {}, 339 | "source": [ 340 | "As we can see from the charts, each distance metric produces a heat map that represents different similarities between the products, and on a different scale. While each distance metric can be used to interpret whether two products are similar or not based on the metric's value, it is difficult to determine a true measure of similarity when comparing the results across different distance metrics." 341 | ] 342 | }, 343 | { 344 | "cell_type": "markdown", 345 | "id": "f5314124-5a7e-4865-9cd8-3b523d257a99", 346 | "metadata": {}, 347 | "source": [ 348 | "** **\n", 349 | "### How to choose the metric?\n", 350 | "\n", 351 | "There is no single \"true\" answer when it comes to choosing a distance metric, as different distance metrics are better suited for different types of data and different analysis goals. However, there are some factors that can help narrow down the possible distance metrics that might be appropriate for a given situation. Some things to consider when choosing a distance metric include:\n", 352 | "\n", 353 | "- The type of data you are working with: Some distance metrics are more appropriate for continuous data, while others are better suited for categorical or binary data.\n", 354 | "- The characteristics of the data: Different distance metrics are sensitive to different aspects of the data, such as the magnitudes of differences between attributes or the angles between attributes. Consider which characteristics of the data are most important to your analysis and choose a distance metric that is sensitive to these characteristics.\n", 355 | "- The goals of your analysis: Different distance metrics can highlight different patterns or relationships in the data, so consider what you are trying to learn from your analysis and choose a distance metric that is well-suited to this purpose.\n", 356 | "\n", 357 | "Personally, I often use the following chart as a starting point when choosing a distance metric.\n", 358 | "\n", 359 | "![flowchart](similaritymeasures.png)\n", 360 | "\n", 361 | "Again, it is important to carefully consider the data type and characteristics when selecting a similarity metric, as well as the specific goals of the analysis." 362 | ] 363 | } 364 | ], 365 | "metadata": { 366 | "kernelspec": { 367 | "display_name": "Python 3 (ipykernel)", 368 | "language": "python", 369 | "name": "python3" 370 | }, 371 | "language_info": { 372 | "codemirror_mode": { 373 | "name": "ipython", 374 | "version": 3 375 | }, 376 | "file_extension": ".py", 377 | "mimetype": "text/x-python", 378 | "name": "python", 379 | "nbconvert_exporter": "python", 380 | "pygments_lexer": "ipython3", 381 | "version": "3.9.16" 382 | } 383 | }, 384 | "nbformat": 4, 385 | "nbformat_minor": 5 386 | } 387 | -------------------------------------------------------------------------------- /general-data-science/similarities-measures/similaritymeasures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/general-data-science/similarities-measures/similaritymeasures.png -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/data/training_data.csv: -------------------------------------------------------------------------------- 1 | base,ref,similarity 2 | dresser,data scientist,0.5 3 | clubhost,data scientist,0.5 4 | co-pilot,data analyst,0.5 5 | data analyst,textile quality manager,0.5 6 | data analyst,tracer powder blender,0.5 7 | data analyst,pottery and porcelain caster,0.5 8 | data analyst,equine dental technician,0.5 9 | data analyst," Equine dental technicians provide routine equine dental care, using appropriate equipment in accordance with national legislation. 10 | ",0.5 11 | data analyst,vessel assembly inspector,0.5 12 | data analyst,bacteriology technician,0.5 13 | data analyst,mover,0.5 14 | data scientist,manager di fondi pensione,0.5 15 | data scientist,takelaar,0.5 16 | data scientist,tapijtknoper,0.5 17 | data scientist,technicus waterleidingssystemen,0.5 18 | data scientist,textile quality manager,0.5 19 | data scientist,nailing machine operator,0.5 20 | data scientist,hot foil operator,0.5 21 | data scientist,I manager di fondi pensione coordinano i fondi pensione al fine di fornire prestazioni pensionistiche a individui o organizzazioni. Assicurano la gestione giornaliera dei fondi pensione e definiscono la politica strategica per lo sviluppo di nuovi pacchetti pensionistici.,0.5 22 | data scientist,reisagent,0.5 23 | data scientist,matrassenmaker,0.5 24 | data scientist,emailleur,0.5 25 | data scientist,meester-koffiebrander,0.5 26 | data scientist,operatore di macchine per la produzione cartotecnica/operatrice su macchine per la produzione cartotecnica,0.5 27 | data scientist,watch and clock repairer,0.5 28 | data scientist,tapijtlegger,0.5 29 | data scientist,credit union manager,0.5 30 | data scientist,"Textile quality managers implement, manage and promote quality systems. They make sure that the textile products adhere to the quality standards of the organisation. Textile quality managers therefore inspect textile production lines and products.",0.5 31 | data scientist,assemblagetechnicus accusystemen,0.5 32 | data scientist,yeast distiller,0.5 33 | data scientist,"Hot foil operators tend machines which apply a metallic foil on other materials using pressure cylinders and heating. They also mix colors, set up the appropriate machinery equipment and monitor printing.",0.5 34 | data scientist,addetto alle operazioni fiscali/addetta alle operazioni fiscali,0.5 35 | data scientist,viskooitechnicus,0.5 36 | data scientist,teamleider in een mijn,0.5 37 | rental manager,data scientist,0.5 38 | train preparer,data scientist,0.5 39 | ceiling installer,data analyst,0.5 40 | igienista dentale,data scientist,0.5 41 | cabin crew manager,data scientist,0.5 42 | incisore su metallo,data scientist,0.5 43 | justice of the peace,data analyst,0.5 44 | import export manager,data scientist,0.5 45 | conducente di autocarri,data scientist,0.5 46 | conducente di autocarri,"I data scientist scoprono e interpretano fonti ricche di dati, gestiscono grandi quantità di dati, ne aggregano le fonti, garantiscono la coerenza degli insiemi di dati e creano visualizzazioni per contribuire alla loro comprensione. Costruiscono modelli matematici che utilizzano dati, presentano e comunicano informazioni e conoscenze sui dati agli specialisti e agli scienziati nella loro squadra e, se necessario, a un pubblico non specializzato e raccomandano modalità di applicazione dei dati.",0.5 47 | footwear CAD patternmaker,data analyst,0.5 48 | ufficiale di stato civile,data scientist,0.5 49 | dental instrument assembler,data scientist,0.5 50 | waste management supervisor,data analyst,0.5 51 | carrosserie- en voertuigbouwer,data scientist,0.5 52 | fuel station specialised seller,data analyst,0.5 53 | productieleider chemische industrie,data scientist,0.5 54 | marinaio addetto al servizio di coperta,data scientist,0.5 55 | allenatore sportivo/allenatrice sportiva,data scientist,0.5 56 | allenatore sportivo/allenatrice sportiva,"I data scientist scoprono e interpretano fonti ricche di dati, gestiscono grandi quantità di dati, ne aggregano le fonti, garantiscono la coerenza degli insiemi di dati e creano visualizzazioni per contribuire alla loro comprensione. Costruiscono modelli matematici che utilizzano dati, presentano e comunicano informazioni e conoscenze sui dati agli specialisti e agli scienziati nella loro squadra e, se necessario, a un pubblico non specializzato e raccomandano modalità di applicazione dei dati.",0.5 57 | water conservation technician supervisor,data scientist,0.5 58 | supervisore di assemblaggio di veicoli a motore,data scientist,0.5 59 | tecnico della qualità dei prodotti di pelletteria,data scientist,0.5 60 | responsabile della distribuzione di macchine e attrezzature agricole,data scientist,0.5 61 | "wholesale merchant in agricultural raw materials, seeds and animal feeds",data analyst,0.5 62 | confezionatore caseario artigianale /confezionatrice casearia artigianale,data scientist,0.5 63 | confezionatore caseario artigianale /confezionatrice casearia artigianale,"I data scientist scoprono e interpretano fonti ricche di dati, gestiscono grandi quantità di dati, ne aggregano le fonti, garantiscono la coerenza degli insiemi di dati e creano visualizzazioni per contribuire alla loro comprensione. Costruiscono modelli matematici che utilizzano dati, presentano e comunicano informazioni e conoscenze sui dati agli specialisti e agli scienziati nella loro squadra e, se necessario, a un pubblico non specializzato e raccomandano modalità di applicazione dei dati.",0.5 64 | import-exportmanager ijzerwaren en producten voor loodgieterij en verwarming,data scientist,0.5 65 | addetto all’assemblaggio di strumenti di precisione/addetta all’assemblaggio di strumenti di precisione,data scientist,0.5 66 | data analyst,"Data analysts import, inspect, clean, transform, validate, model, or interpret collections of data with regard to the business goals of the company. They ensure that the data sources and repositories provide consistent and reliable data. Data analysts use different algorithms and IT tools as demanded by the situation and the current data. They might prepare reports in the form of visualisations such as graphs, charts, and dashboards.",1.0 67 | data scientist,"Data scientists find and interpret rich data sources, manage large amounts of data, merge data sources, ensure consistency of data-sets, and create visualisations to aid in understanding data. They build mathematical models using data, present and communicate data insights and findings to specialists and scientists in their team and if required, to a non-expert audience, and recommend ways to apply the data.",1.0 68 | data scientist,"Data scientists zoeken en interpreteren rijke gegevensbronnen, beheren grote hoeveelheden gegevens, voegen gegevensbronnen samen, zorgen voor de consistentie van datasets en creëren visualisaties om te helpen gegevens te begrijpen. Zij bouwen wiskundige modellen op basis van data, presenteren en communiceren gegevensinzichten en bevindingen aan specialisten en wetenschappers in hun team en, indien nodig, aan een niet-deskundig publiek, en bevelen manieren aan om de data toe te passen.",1.0 69 | data scientist,"I data scientist scoprono e interpretano fonti ricche di dati, gestiscono grandi quantità di dati, ne aggregano le fonti, garantiscono la coerenza degli insiemi di dati e creano visualizzazioni per contribuire alla loro comprensione. Costruiscono modelli matematici che utilizzano dati, presentano e comunicano informazioni e conoscenze sui dati agli specialisti e agli scienziati nella loro squadra e, se necessario, a un pubblico non specializzato e raccomandano modalità di applicazione dei dati.",1.0 70 | cosmologist,cosmology data scientist,0.74681668889336494 71 | data analyst,data storage analyst,0.74681668889336494 72 | data analyst,data warehouse analyst,0.74681668889336494 73 | data analyst,data warehousing analyst,0.74681668889336494 74 | meter reader,metering data analyst,0.74681668889336494 75 | statistician,statistical data analyst,0.74681668889336494 76 | data scientist,esperta di dati,0.74681668889336494 77 | data scientist,data engineer,0.74681668889336494 78 | data scientist,data-scientist,0.74681668889336494 79 | data scientist,data research scientist,0.74681668889336494 80 | data scientist,esperto di dati,0.74681668889336494 81 | data scientist,data expert,0.74681668889336494 82 | data scientist,data analyst,0.74681668889336494 83 | data scientist,research data scientist,0.74681668889336494 84 | data scientist,research analist,0.74681668889336494 85 | data scientist,research data scientist,0.74681668889336494 86 | data scientist,analista dei dati di ricerca,0.74681668889336494 87 | data scientist,business data scientist,0.74681668889336494 88 | analista dei dati,data analyst,0.74681668889336494 89 | call centre analyst,sales data analyst,0.74681668889336494 90 | call centre analyst,CRM data analyst,0.74681668889336494 91 | call centre analyst,customer data analyst,0.74681668889336494 92 | call centre analyst,senior data analyst,0.74681668889336494 93 | call centre analyst,assistant data analyst,0.74681668889336494 94 | call centre analyst,trainee data analyst,0.74681668889336494 95 | call centre analyst,graduate data analyst,0.74681668889336494 96 | call centre analyst,marketing data analyst,0.74681668889336494 97 | call centre analyst,IT data analyst,0.74681668889336494 98 | analyste de données,data analyst,0.74681668889336494 99 | bioinformatics scientist,data scientist,0.74681668889336494 100 | scientifique des données,data scientist,0.74681668889336494 -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/domain_adaption_fine_tune_nlp_model.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cba912be-879a-4a9b-a7e9-180f42555cb9", 6 | "metadata": {}, 7 | "source": [ 8 | "## Domain Adaption: Fine-Tune Pre-Trained NLP Models\n", 9 | "\n", 10 | "### Introduction\n", 11 | "In today's world, the availability of pre-trained NLP models has greatly simplified the interpretation of textual data using deep learning techniques. However, while these models excel in general tasks, they often lack adaptability to specific domains. This comprehensive guide aims to walk you through the process of fine-tuning pre-trained NLP models to achieve improved performance in a particular domain.\n", 12 | "\n", 13 | "#### Motivation\n", 14 | "Although pre-trained NLP models like BERT and the Universal Sentence Encoder (USE) are effective in capturing linguistic intricacies, their performance in domain-specific applications can be limited due to the diverse range of datasets they are trained on. This limitation becomes evident when analyzing relationships within a specific domain. \n", 15 | "\n", 16 | "For example, when working with employment data, we expect the model to recognize the closer proximity between the roles of 'Data Scientist' and 'Machine Learning Engineer', or the stronger association between 'Python' and 'TensorFlow'. Unfortunately, general-purpose models often miss these nuanced relationships.\n", 17 | "\n", 18 | "To address this issue, we can fine-tune pre-trained models with high-quality, domain-specific datasets. This adaptation process significantly enhances the model's performance and precision, fully unlocking the potential of the NLP model.\n", 19 | "\n", 20 | "When dealing with large pre-trained NLP models, it is advisable to initially deploy the base model and consider fine-tuning only if its performance falls short for the specific problem at hand.\n", 21 | " \n", 22 | "This tutorial focuses on fine-tuning the Universal Sentence Encoder (USE) model using easily accessible open-source data.\n", 23 | "\n", 24 | "### Theoretical Overview\n", 25 | "Fine-tuning an ML model can be achieved through various strategies, such as supervised learning and reinforcement learning. In this tutorial, we will concentrate on a one(few)-shot learning approach combined with a siamese architecture for the fine-tuning process.\n", 26 | "\n", 27 | "#### Methodology\n", 28 | "In this tutorial, we utilize a siamese neural network, which is a specific type of Artificial Neural Network. This network leverages shared weights while simultaneously processing two distinct input vectors to compute comparable output vectors. Inspired by one-shot learning, this approach has proven to be particularly effective in capturing semantic similarity, although it may require longer training times and lack probabilistic output.\n", 29 | "\n", 30 | "A Siamese Neural Network creates an 'embedding space' where related concepts are positioned closely, enabling the model to better discern semantic relations.\n", 31 | "- Twin Branches and Shared Weights: The architecture consists of two identical branches, each containing an embedding layer with shared weights. These dual branches handle two inputs simultaneously, either similar or dissimilar.\n", 32 | "- Similarity and Transformation: The inputs are transformed into vector embeddings using the pre-trained NLP model. The architecture then calculates the similarity between the vectors. The similarity score, ranging between -1 and 1, quantifies the angular distance between the two vectors, serving as a metric for their semantic similarity.\n", 33 | "- Contrastive Loss and Learning: The model's learning is guided by the \"Contrastive Loss,\" which is the difference between the expected output (similarity score from the training data) and the computed similarity. This loss guides the adjustment of the model's weights to minimize the loss and enhance the quality of the learned embeddings." 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "id": "13a3c7e3-4b5f-4369-b6b0-e0ea5b43f425", 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "import pandas as pd\n", 44 | "import math\n", 45 | "import tensorflow as tf\n", 46 | "import tensorflow_hub as hub\n", 47 | "from tensorflow import keras\n", 48 | "from tensorflow_text import SentencepieceTokenizer\n", 49 | "import os\n", 50 | "from datetime import datetime\n", 51 | "import numpy as np\n", 52 | "from utils import *" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "9c770e7f-5a4e-42d7-89d6-a8eb0eec8210", 58 | "metadata": {}, 59 | "source": [ 60 | "** **\n", 61 | "#### Data Overview\n", 62 | "\n", 63 | "For the fine-tuning of pre-trained NLP models using this method, the training data should consist of pairs of text strings accompanied by similarity scores between them. \n", 64 | "\n", 65 | "In this tutorial, we use a dataset sourced from the ESCO classification dataset, which has been transformed to generate similarity scores based on the relationships between different data elements.\n", 66 | "\n", 67 | "Preparing the training data is a crucial step in the fine-tuning process. It is assumed that you have access to the required data and a method to transform it into the specified format. Since the focus of this article is to demonstrate the fine-tuning process, we will omit the details of how the data was generated using the ESCO dataset.\n", 68 | "\n", 69 | "Let's start by examining the training data:" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "id": "94c76e58-475b-49b4-a97e-5c7b1e6e2630", 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "# The data from this file is stored in the variable \"data\".\n", 80 | "data = pd.read_csv(\"./data/training_data.csv\")\n", 81 | "\n", 82 | "# Use the head function on the DataFrame to display its first 5 rows.\n", 83 | "data.head()\n" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "id": "20dc8c3c-2835-4472-894f-12239de8173b", 89 | "metadata": {}, 90 | "source": [ 91 | "** **\n", 92 | "#### Baseline Model\n", 93 | "To begin, we establish the multilingual universal sentence encoder as our baseline model. It is essential to set this baseline before proceeding with the fine-tuning process.\n", 94 | "\n", 95 | "For this tutorial, we will use the STS benchmark and a sample similarity visualization as metrics to evaluate the changes and improvements achieved through the fine-tuning process.\n", 96 | "\n", 97 | "The STS Benchmark dataset consists of English sentence pairs, each associated with a similarity score. During the model training process, we evaluate the model's performance on this benchmark set. The persisted scores for each training run are the Pearson correlation between the predicted similarity scores and the actual similarity scores in the dataset. \n", 98 | "\n", 99 | "These scores ensure that as the model is fine-tuned with our context-specific training data, it maintains some level of generalizability." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "f643d10f-716e-4982-984e-48f0bbf2e3df", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# Loads the Universal Sentence Encoder Multilingual module from TensorFlow Hub.\n", 110 | "base_model_url = \"https://tfhub.dev/google/universal-sentence-encoder-multilingual/3\"\n", 111 | "base_model = tf.keras.Sequential([\n", 112 | " hub.KerasLayer(base_model_url,\n", 113 | " input_shape=[],\n", 114 | " dtype=tf.string,\n", 115 | " trainable=False)\n", 116 | "])\n", 117 | "\n", 118 | "# Defines a list of test sentences. These sentences represent various job titles.\n", 119 | "test_text = ['Data Scientist', 'Data Analyst', 'Data Engineer',\n", 120 | " 'Nurse Practitioner', 'Registered Nurse', 'Medical Assistant',\n", 121 | " 'Social Media Manager', 'Marketing Strategist', 'Product Marketing Manager']\n", 122 | "\n", 123 | "# Creates embeddings for the sentences in the test_text list. \n", 124 | "# The np.array() function is used to convert the result into a numpy array.\n", 125 | "# The .tolist() function is used to convert the numpy array into a list, which might be easier to work with.\n", 126 | "vectors = np.array(base_model.predict(test_text)).tolist()\n", 127 | "\n", 128 | "# Calls the plot_similarity function to create a similarity plot.\n", 129 | "plot_similarity(test_text, vectors, 90, \"base model\")\n", 130 | "\n", 131 | "# Computes STS benchmark score for the base model\n", 132 | "pearsonr = sts_benchmark(base_model)\n", 133 | "print(\"STS Benachmark: \" + str(pearsonr))" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "id": "51a178d6-760d-4c0b-8994-0bac82118a98", 139 | "metadata": {}, 140 | "source": [ 141 | "** **\n", 142 | "#### Fine Tuning the Model\n", 143 | "The next step involves constructing the siamese model architecture using the baseline model and fine-tuning it with our domain-specific data." 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "id": "f65eca14-f5c4-41f5-8048-ce7480759a33", 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "# Load the pre-trained word embedding model\n", 154 | "embedding_layer = hub.load(base_model_url)\n", 155 | "\n", 156 | "# Create a Keras layer from the loaded embedding model\n", 157 | "shared_embedding_layer = hub.KerasLayer(embedding_layer, trainable=True)\n", 158 | "\n", 159 | "# Define the inputs to the model\n", 160 | "left_input = keras.Input(shape=(), dtype=tf.string)\n", 161 | "right_input = keras.Input(shape=(), dtype=tf.string)\n", 162 | "\n", 163 | "# Pass the inputs through the shared embedding layer\n", 164 | "embedding_left_output = shared_embedding_layer(left_input)\n", 165 | "embedding_right_output = shared_embedding_layer(right_input)\n", 166 | "\n", 167 | "# Compute the cosine similarity between the embedding vectors\n", 168 | "cosine_similarity = tf.keras.layers.Dot(axes=-1, normalize=True)(\n", 169 | " [embedding_left_output, embedding_right_output]\n", 170 | ")\n", 171 | "\n", 172 | "# Convert the cosine similarity to angular distance\n", 173 | "pi = tf.constant(math.pi, dtype=tf.float32)\n", 174 | "clip_cosine_similarities = tf.clip_by_value(\n", 175 | " cosine_similarity, -0.99999, 0.99999\n", 176 | ")\n", 177 | "acos_distance = 1.0 - (tf.acos(clip_cosine_similarities) / pi)\n", 178 | "\n", 179 | "# Package the model\n", 180 | "encoder = tf.keras.Model([left_input, right_input], acos_distance)\n", 181 | "\n", 182 | "# Compile the model\n", 183 | "encoder.compile(\n", 184 | " optimizer=tf.keras.optimizers.Adam(\n", 185 | " learning_rate=0.00001,\n", 186 | " beta_1=0.9,\n", 187 | " beta_2=0.9999,\n", 188 | " epsilon=0.0000001,\n", 189 | " amsgrad=False,\n", 190 | " clipnorm=1.0,\n", 191 | " name=\"Adam\",\n", 192 | " ),\n", 193 | " loss=tf.keras.losses.MeanSquaredError(\n", 194 | " reduction=keras.losses.Reduction.AUTO, name=\"mean_squared_error\"\n", 195 | " ),\n", 196 | " metrics=[\n", 197 | " tf.keras.metrics.MeanAbsoluteError(),\n", 198 | " tf.keras.metrics.MeanAbsolutePercentageError(),\n", 199 | " ],\n", 200 | ")\n", 201 | "\n", 202 | "# Print the model summary\n", 203 | "encoder.summary()" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "id": "250e87af-306a-47b9-8349-ca64c54f06ac", 210 | "metadata": { 211 | "scrolled": true 212 | }, 213 | "outputs": [], 214 | "source": [ 215 | "early_stop = keras.callbacks.EarlyStopping(\n", 216 | " monitor=\"loss\", patience=3, min_delta=0.001\n", 217 | " )\n", 218 | "logdir = os.path.join(\n", 219 | " \".\",\n", 220 | " \"logs/fit/\" + datetime.now().strftime(\"%Y%m%d-%H%M%S\"),\n", 221 | " )\n", 222 | "tensorboard_callback = keras.callbacks.TensorBoard(log_dir=logdir)\n", 223 | "\n", 224 | "# Model Input\n", 225 | "left_inputs, right_inputs, similarity = process_model_input(data)\n", 226 | "\n", 227 | "history = encoder.fit(\n", 228 | " [left_inputs, right_inputs],\n", 229 | " similarity,\n", 230 | " batch_size=8,\n", 231 | " epochs=20,\n", 232 | " validation_split=0.2,\n", 233 | " callbacks=[early_stop, tensorboard_callback],\n", 234 | " )\n", 235 | "\n", 236 | "inputs = keras.Input(shape=[], dtype=tf.string)\n", 237 | "embedding = hub.KerasLayer(embedding_layer)(inputs)\n", 238 | "\n", 239 | "tuned_model = keras.Model(inputs=inputs, outputs=embedding)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "id": "06975f60-e3a1-4c46-b5fa-3bc2512061a6", 245 | "metadata": {}, 246 | "source": [ 247 | "** **\n", 248 | "#### Evaluation\n", 249 | "\n", 250 | "Now that we have the fine-tuned model, let's re-evaluate it and compare the results to those of the base model." 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": null, 256 | "id": "3260ff05-07aa-4c55-9509-4ca60fada326", 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "# Creates embeddings for the sentences in the test_text list. \n", 261 | "# The np.array() function is used to convert the result into a numpy array.\n", 262 | "# The .tolist() function is used to convert the numpy array into a list, which might be easier to work with.\n", 263 | "vectors = np.array(tuned_model.predict(test_text)).tolist()\n", 264 | "\n", 265 | "# Calls the plot_similarity function to create a similarity plot.\n", 266 | "plot_similarity(test_text, vectors, 90, \"tuned model\")\n", 267 | "\n", 268 | "# Computes STS benchmark score for the tuned model\n", 269 | "pearsonr = sts_benchmark(tuned_model)\n", 270 | "print(\"STS Benachmark: \" + str(pearsonr))" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "id": "8807399d-3360-4d7b-8413-4eb0c033e922", 276 | "metadata": {}, 277 | "source": [ 278 | "Based on fine-tuning the model on the relatively small dataset, the STS benchmark score is comparable to that of the baseline model, indicating that the tuned model still exhibits generalizability. However, the similarity visualization demonstrates strengthened similarity scores between similar titles and a reduction in scores for dissimilar ones." 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "id": "114c50ab-9d12-4c3b-8ea9-f4ca2725efd3", 284 | "metadata": {}, 285 | "source": [ 286 | "** **\n", 287 | "### Closing Thoughts\n", 288 | "\n", 289 | "Fine-tuning pre-trained NLP models for domain adaptation is a powerful technique to improve their performance and precision in specific contexts. By utilizing quality, domain-specific datasets and leveraging siamese neural networks, we can enhance the model's ability to capture semantic similarity.\n", 290 | "\n", 291 | "This tutorial provided a step-by-step guide to the fine-tuning process, using the Universal Sentence Encoder (USE) model as an example. We explored the theoretical framework, data preparation, baseline model evaluation, and the actual fine-tuning process. The results demonstrated the effectiveness of fine-tuning in strengthening similarity scores within a domain.\n", 292 | "\n", 293 | "By following this approach and adapting it to your specific domain, you can unlock the full potential of pre-trained NLP models and achieve better results in your natural language processing tasks" 294 | ] 295 | } 296 | ], 297 | "metadata": { 298 | "kernelspec": { 299 | "display_name": "Python 3 (ipykernel)", 300 | "language": "python", 301 | "name": "python3" 302 | }, 303 | "language_info": { 304 | "codemirror_mode": { 305 | "name": "ipython", 306 | "version": 3 307 | }, 308 | "file_extension": ".py", 309 | "mimetype": "text/x-python", 310 | "name": "python", 311 | "nbconvert_exporter": "python", 312 | "pygments_lexer": "ipython3", 313 | "version": "3.9.16" 314 | } 315 | }, 316 | "nbformat": 4, 317 | "nbformat_minor": 5 318 | } 319 | -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/logs/fit/20230630-152712/train/events.out.tfevents.1688153232.Shashanks-MacBook-Pro-2.local.44453.0.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/embedding-models/logs/fit/20230630-152712/train/events.out.tfevents.1688153232.Shashanks-MacBook-Pro-2.local.44453.0.v2 -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/logs/fit/20230630-152712/validation/events.out.tfevents.1688153249.Shashanks-MacBook-Pro-2.local.44453.1.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/embedding-models/logs/fit/20230630-152712/validation/events.out.tfevents.1688153249.Shashanks-MacBook-Pro-2.local.44453.1.v2 -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/packages/tensorflow_text-2.10.0-cp39-cp39-macosx_11_0_arm64.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/embedding-models/packages/tensorflow_text-2.10.0-cp39-cp39-macosx_11_0_arm64.whl -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "embedding-models" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Shashank Kapadia "] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = ">=3.9,<3.10" 10 | jupyterlab = "^4.0.2" 11 | tensorflow-hub = "^0.13.0" 12 | tensorflow = [ 13 | { version = "2.10.0", platform = "linux" }, 14 | ] 15 | tensorflow-macos = [ 16 | { version = "2.10.0", platform = "darwin" }, 17 | ] 18 | #tensorflow-text = "^2.10.0" 19 | tensorflow-text = [ 20 | {file = "packages/tensorflow_text-2.10.0-cp39-cp39-macosx_11_0_arm64.whl", platform = "darwin"}, 21 | ] 22 | pandas = "^2.0.3" 23 | seaborn = "^0.12.2" 24 | tqdm = "^4.65.0" 25 | 26 | 27 | [build-system] 28 | requires = ["poetry-core"] 29 | build-backend = "poetry.core.masonry.api" 30 | -------------------------------------------------------------------------------- /natural-language-processing/embedding-models/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import seaborn as sns 3 | import matplotlib.pyplot as plt 4 | import tensorflow as tf 5 | import tqdm 6 | from scipy import stats 7 | import pandas as pd 8 | import os 9 | import math 10 | 11 | 12 | def plot_similarity(labels, features, rotation, version): 13 | corr = np.inner(features, features) 14 | sns.set(font_scale=1.2) 15 | g = sns.heatmap( 16 | corr, 17 | xticklabels=labels, 18 | yticklabels=labels, 19 | vmin=0, 20 | vmax=1, 21 | cmap="YlOrRd") 22 | g.set_xticklabels(labels, rotation=rotation) 23 | g.set_title(version) 24 | 25 | def cosine_similarity(vector_1, vector_2): 26 | """ 27 | Compute cosine similarity between two vectors. 28 | 29 | Args: 30 | vector_1 (List[float]): A list of float values representing the first vector. 31 | vector_2 (List[float]): A list of float values representing the second vector. 32 | 33 | Returns: 34 | float: The cosine similarity between the two vectors, which is the dot product of 35 | the two vectors divided by the product of their magnitudes. 36 | """ 37 | sumxx, sumxy, sumyy = 0, 0, 0 38 | for i in range(len(vector_1)): 39 | x = vector_1[i] 40 | y = vector_2[i] 41 | sumxx += x * x 42 | sumyy += y * y 43 | sumxy += x * y 44 | return sumxy / math.sqrt(sumxx * sumyy) 45 | 46 | 47 | def sts_benchmark(model, type="dev"): 48 | """ 49 | Compute the Pearson correlation between predicted cosine similarity scores and human-labeled similarity scores 50 | on the STS benchmark dataset. 51 | 52 | Args: 53 | model (tensorflow.keras.Model): A trained sentence embedding model that takes in an input sentence and 54 | outputs a corresponding sentence embedding. 55 | type (str): The type of STS benchmark dataset to use. Either "dev" for the development dataset or "test" 56 | for the test dataset. Default is "dev". 57 | 58 | Returns: 59 | tuple: A tuple containing the Pearson correlation coefficient and the p-value of the correlation test. 60 | """ 61 | 62 | def _get_sts_dataset(type="test"): 63 | """ 64 | 65 | :param type: 66 | :return: 67 | """ 68 | 69 | sts_dataset = tf.keras.utils.get_file( 70 | fname="Stsbenchmark.tar.gz", 71 | origin="http://ixa2.si.ehu.es/stswiki/images/4/48/Stsbenchmark.tar.gz", 72 | extract=True, 73 | ) 74 | if type == "dev": 75 | data = pd.read_table( 76 | os.path.join( 77 | os.path.dirname(sts_dataset), "stsbenchmark", "sts-dev.csv" 78 | ), 79 | on_bad_lines="skip", 80 | engine="python", 81 | skip_blank_lines=True, 82 | usecols=[4, 5, 6], 83 | names=["sim", "sent_1", "sent_2"], 84 | ) 85 | else: 86 | data = pd.read_table( 87 | os.path.join( 88 | os.path.dirname(sts_dataset), "stsbenchmark", "sts-test.csv" 89 | ), 90 | on_bad_lines="skip", 91 | engine="python", 92 | skip_blank_lines=True, 93 | usecols=[4, 5, 6], 94 | names=["sim", "sent_1", "sent_2"], 95 | ) 96 | 97 | return data 98 | 99 | data = _get_sts_dataset(type=type) 100 | data = data[[isinstance(s, str) for s in data["sent_2"]]].reset_index() 101 | 102 | # prepare data 103 | base_text = [data["sent_1"][i] for i in range(len(data))] 104 | ref_text = [data["sent_2"][i] for i in range(len(data))] 105 | scores = data["sim"].tolist() 106 | 107 | base_vectors = [] 108 | ref_vectors = [] 109 | 110 | # get text vectors from base, tuned, pre-tuned models 111 | for i in range(len(base_text)): 112 | base_vectors.append(list(model.predict([base_text[i]])[0])) 113 | ref_vectors.append(list(model.predict([ref_text[i]])[0])) 114 | 115 | base_cosine_similarity = [ 116 | cosine_similarity(base_vectors[i], ref_vectors[i]) 117 | for i in range(len(base_text)) 118 | ] 119 | return stats.pearsonr(scores, base_cosine_similarity) 120 | 121 | def process_model_input(data): 122 | """ 123 | Processes the input data by reshaping the left and right inputs and converting the similarity values. 124 | 125 | Args: 126 | data: (dict) A dictionary containing the keys "base", "ref", and "similarity", 127 | with values corresponding to the input base text, reference text, and similarity values respectively. 128 | 129 | Returns: 130 | tuple: A tuple of three numpy arrays containing the preprocessed left inputs, right inputs, 131 | and similarity values respectively. 132 | """ 133 | text_list = [list(data["base"].values), list(data["ref"].values)] 134 | left_inputs = np.asarray(text_list[0]) 135 | right_inputs = np.asarray(text_list[1]) 136 | left_inputs = left_inputs.reshape( 137 | left_inputs.shape[0], 138 | ) 139 | right_inputs = right_inputs.reshape( 140 | right_inputs.shape[0], 141 | ) 142 | 143 | # 1 if we inputs are semantically similiar, 0 if not. 144 | # Check the distance function defined as 1-arccos(similiarity)/pi which has range between 1,0 for domain 0 to 1 145 | similarity = np.asarray(list(data["similarity"].values)) 146 | 147 | return left_inputs, right_inputs, similarity 148 | 149 | -------------------------------------------------------------------------------- /natural-language-processing/text-processing/Building Blocks Text Pre-Processing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Building Blocks: Text Pre-Processing\n", 8 | "\n", 9 | "This article is the second of more to come articles on Natural Language Processing. The purpose of this series of articles is to document my journey as I learn about this subject, as well as help others gain efficiency from it.\n", 10 | "\n", 11 | "In the last article of our series, we introduced the concept of Natural Language Processing, you can read it here, and now you probably want to try it yourself, right? Great! Without further ado, let's dive in to the building blocks for statistical natural language processing. \n", 12 | "\n", 13 | "In this article, we'll introduce the key concepts, along with practical implementation in Python and the challenges to keep in mind at the time of application.\n", 14 | "\n", 15 | "**References:**\n", 16 | "- A General Approach to Preprocessing Text Data — KDnuggets. https://www.kdnuggets.com/2017/12/general-approach-preprocessing-text-data.html\n", 17 | "- Tokenization — Stanford NLP Group. https://nlp.stanford.edu/IR-book/html/htmledition/tokenization-1.html\n", 18 | "- Text Mining in Bovine Diseases — ijcaonline.org. https://www.ijcaonline.org/volume6/number10/pxc3871454.pdf\n", 19 | "- Stemming and lemmatization — Stanford NLP Group. https://nlp.stanford.edu/IR-book/html/htmledition/stemming-and-lemmatization-1.html\n", 20 | "** **" 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "metadata": {}, 26 | "source": [ 27 | "### Text Normalization\n", 28 | "\n", 29 | "Normalizing the text means converting it to a more convenient, standard form before performing turning it to features for higher level modeling. Think of this step as converting human readable language into a form that is machine readable.\n", 30 | "\n", 31 | "The standard framework to normalize the text includes:\n", 32 | "1. Tokenization\n", 33 | "2. Stop Words Removal\n", 34 | "3. Morphological Normalization\n", 35 | "4. Collocation\n", 36 | "\n", 37 | "Data preprocessing consists of a number of steps, any number of which may or not apply to a given task. More generally, in this article we'll discuss some predetermined body of text, and perform some basic transformative analysis that can be used for performing further, more meaningful natural language processing\n", 38 | "\n", 39 | "** **\n", 40 | "#### Tokenization\n", 41 | "\n", 42 | "Given a character sequence and a defined document unit (blurb of texts), tokenization is the task of chopping it up into pieces, called tokens, perhaps at the same time throwing away certain characters/words, such as punctuation. Ordinarily, there are two types of tokenization:\n", 43 | "\n", 44 | "1. Word Tokenization: Used to separate words via unique space character. Depending on the application, word tokenization may also tokenize multi-word expressions like New York. This is often times is closely tied to a process called Named Entity Recognition. Later in this tutorial, we will look at Collocation (Phrase) Modeling that helps address part of this challenge\n", 45 | "\n", 46 | "2. Sentence Tokenization/Segmentation: Along with word tokenization, sentence segmentation is a crucial step in text processing. This is usually performed based on punctuations such as \".\", \"?\", \"!\" as they tend to mark the sentence boundaries\n", 47 | "\n", 48 | "**Challenges:**\n", 49 | "- The use of abbreviations may prompt the tokenizer to detect a sentence boundary where there is none. \n", 50 | "- Numbers, special characters, hyphenation, and capitalization. In the expressions \"don't,\" \"I'd,\" \"John's\" do we have one, two or three tokens?" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "import nltk\n", 60 | "\n", 61 | "nltk.download('punkt')\n", 62 | "nltk.download('stopwords')\n", 63 | "nltk.download('wordnet')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "from nltk.tokenize import sent_tokenize, word_tokenize\n", 73 | "\n", 74 | "#Sentence Tokenization\n", 75 | "print ('Following is the list of sentences tokenized from the sample review\\n')\n", 76 | "\n", 77 | "sample_text = \"\"\"The first time I ate here I honestly was not that impressed. I decided to wait a bit and give it another chance. \n", 78 | "I have recently eaten there a couple of times and although I am not convinced that the pricing is particularly on point the two mushroom and \n", 79 | "swiss burgers I had were honestly very good. The shakes were also tasty. Although Mad Mikes is still my favorite burger around, \n", 80 | "you can do a heck of a lot worse than Smashburger if you get a craving\"\"\"\n", 81 | "\n", 82 | "tokenize_sentence = sent_tokenize(sample_text)\n", 83 | "\n", 84 | "print (tokenize_sentence)\n", 85 | "print ('---------------------------------------------------------\\n')\n", 86 | "print ('Following is the list of words tokenized from the sample review sentence\\n')\n", 87 | "tokenize_words = word_tokenize(tokenize_sentence[1])\n", 88 | "print (tokenize_words)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "** **\n", 96 | "#### Stop Words Removal\n", 97 | "Often, there are a few ubiquitous words which would appear to be of little value in helping the purpose of analysis but increases the dimensionality of feature set, are excluded from the vocabulary entirely as the part of stop words removal process. There are two considerations usually that motivate this removal.\n", 98 | "\n", 99 | "1. Irrelevance: Allows one to analyze only on content-bearing words. Stopwords, also called empty words because they generally do not bear much meaning, introduce noise in the analysis/modeling process\n", 100 | "2. Dimension: Removing the stopwords also allows one to reduce the tokens in documents significantly, and thereby decreasing feature dimension\n", 101 | "\n", 102 | "**Challenges:**\n", 103 | "\n", 104 | "Converting all characters into lowercase letters before stopwords removal process can introduce ambiguity in the text, and sometimes entirely changing the meaning of it. For example, with the expressions \"US citizen\" will be viewed as \"us citizen\" or \"IT scientist\" as \"it scientist\". Since both *us* and *it* are normally considered stop words, it would result in an inaccurate outcome. The strategy regarding the treatment of stopwords can thus be refined by identifying that \"US\" and \"IT\" are not pronouns in the above examples, through a part-of-speech tagging step." 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "from nltk.corpus import stopwords\n", 114 | "from nltk.tokenize import word_tokenize\n", 115 | "\n", 116 | "# define the language for stopwords removal\n", 117 | "stopwords = set(stopwords.words(\"english\"))\n", 118 | "print (\"\"\"{0} stop words\"\"\".format(len(stopwords)))\n", 119 | "\n", 120 | "tokenize_words = word_tokenize(sample_text)\n", 121 | "filtered_sample_text = [w for w in tokenize_words if not w in stopwords]\n", 122 | "\n", 123 | "print ('\\nOriginal Text:')\n", 124 | "print ('------------------\\n')\n", 125 | "print (sample_text)\n", 126 | "print ('\\n Filtered Text:')\n", 127 | "print ('------------------\\n')\n", 128 | "print (' '.join(str(token) for token in filtered_sample_text))" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "** **\n", 136 | "#### Morphological Normalization\n", 137 | "Morphology, in general, is the study of the way words are built up from smaller meaning-bearing units, morphomes. For example, dogs consists of two morphemes: dog and s\n", 138 | "\n", 139 | "Two commonly used techniques for text normalization are:\n", 140 | "\n", 141 | "1. Stemming: The procedure aims to identify the stem of a word and use it in lieu of the word itself. The most popular algorithm for stemming English, and one that has repeatedly been shown to be empirically very effective, is Porter's algorithm. The entire algorithm is too long and intricate to present here, but you can find details here\n", 142 | "2. Lemmatization: This process refers to doing things correctly with the use of vocabulary and morphological analysis of words, typically aiming to remove inflectional endings only and to return the base or dictionary form of a word, which is known as the lemma.\n", 143 | "\n", 144 | "If confronted with the token saw, stemming might return just s, whereas lemmatization would attempt to return either see or saw depending on whether the use of the token was as a verb or a noun" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "from nltk.stem import PorterStemmer\n", 154 | "from nltk.stem import WordNetLemmatizer\n", 155 | "from nltk.tokenize import word_tokenize\n", 156 | "\n", 157 | "ps = PorterStemmer()\n", 158 | "lemmatizer = WordNetLemmatizer()\n", 159 | "\n", 160 | "tokenize_words = word_tokenize(sample_text)\n", 161 | "\n", 162 | "stemmed_sample_text = []\n", 163 | "for token in tokenize_words:\n", 164 | " stemmed_sample_text.append(ps.stem(token))\n", 165 | "\n", 166 | "lemma_sample_text = []\n", 167 | "for token in tokenize_words:\n", 168 | " lemma_sample_text.append(lemmatizer.lemmatize(token))\n", 169 | " \n", 170 | "print ('\\nOriginal Text:')\n", 171 | "print ('------------------\\n')\n", 172 | "print (sample_text)\n", 173 | "\n", 174 | "print ('\\nFiltered Text: Stemming')\n", 175 | "print ('------------------\\n')\n", 176 | "print (' '.join(str(token) for token in stemmed_sample_text))\n", 177 | "\n", 178 | "print ('\\nFiltered Text: Lemmatization')\n", 179 | "print ('--------------------------------\\n')\n", 180 | "print (' '.join(str(token) for token in lemma_sample_text))" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "** **\n", 188 | "**Challenges:**\n", 189 | "\n", 190 | "Often, full morphological analysis produces at most very modest benefits for analysis. Neither form of normalization improve language information performance in aggregate, both from relevance and dimensionality reduction standpoint - at least not for the following situations:" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [ 199 | "from nltk.stem import PorterStemmer\n", 200 | "words = [\"operate\", \"operating\", \"operates\", \"operation\", \"operative\", \"operatives\", \"operational\"]\n", 201 | "\n", 202 | "ps = PorterStemmer()\n", 203 | "\n", 204 | "for token in words:\n", 205 | " print (ps.stem(token))" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": {}, 211 | "source": [ 212 | "** **\n", 213 | "As an example of what can go wrong, note that the Porter stemmer stems all of the following words to oper\n", 214 | "However, since operate in its various forms is a common verb, we would expect to lose considerable precision:\n", 215 | "- operational AND research\n", 216 | "- operating AND system\n", 217 | "- operative AND dentistry\n", 218 | "\n", 219 | "For cases like these, moving to using a lemmatizer would not completely fix the problem because particular inflectional forms are used in specific collocations. Getting better value from term normalization depends more on pragmatic issues of word use than on formal issues of linguistic morphology" 220 | ] 221 | } 222 | ], 223 | "metadata": { 224 | "environment": { 225 | "name": "common-cpu.m49", 226 | "type": "gcloud", 227 | "uri": "gcr.io/deeplearning-platform-release/base-cpu:m49" 228 | }, 229 | "kernelspec": { 230 | "display_name": "Python 3 (ipykernel)", 231 | "language": "python", 232 | "name": "python3" 233 | }, 234 | "language_info": { 235 | "codemirror_mode": { 236 | "name": "ipython", 237 | "version": 3 238 | }, 239 | "file_extension": ".py", 240 | "mimetype": "text/x-python", 241 | "name": "python", 242 | "nbconvert_exporter": "python", 243 | "pygments_lexer": "ipython3", 244 | "version": "3.10.6" 245 | } 246 | }, 247 | "nbformat": 4, 248 | "nbformat_minor": 4 249 | } 250 | -------------------------------------------------------------------------------- /natural-language-processing/text-processing/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "text-processing" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Shashank Kapadia "] 6 | readme = "README.md" 7 | packages = [{include = "text_processing"}] 8 | 9 | [tool.poetry.dependencies] 10 | python = "^3.10" 11 | jupyterlab = "^3.5.2" 12 | nltk = "^3.8.1" 13 | 14 | 15 | [build-system] 16 | requires = ["poetry-core"] 17 | build-backend = "poetry.core.masonry.api" 18 | -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/Evaluate Topic Models.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Evaluate Topic Model in Python: Latent Dirichlet Allocation (LDA)\\\n", 8 | "##### A step-by-step guide to building interpretable topic models\n", 9 | "\n", 10 | "** **\n", 11 | "*Preface: This article aims to provide consolidated information on the underlying topic and is not to be considered as the original work. The information and the code are repurposed through several online articles, research papers, books, and open-source code*\n", 12 | "** **\n", 13 | "\n", 14 | "In the previous [article](https://towardsdatascience.com/end-to-end-topic-modeling-in-python-latent-dirichlet-allocation-lda-35ce4ed6b3e0), I introduced the concept of topic modeling and walked through the code for developing your first topic model using Latent Dirichlet Allocation (LDA) method in the python using Gensim implementation.\n", 15 | "\n", 16 | "Pursuing on that understanding, in this article, we’ll go a few steps deeper by outlining the framework to quantitatively evaluate topic models through the measure of topic coherence and share the code template in python using Gensim implementation to allow for end-to-end model development.\n", 17 | "\n", 18 | "### Why evaluate topic models?\n", 19 | "\n", 20 | "![img](https://tinyurl.com/y3xznjwq)\n", 21 | "\n", 22 | "We know probabilistic topic models, such as LDA, are popular tools for text analysis, providing both a predictive and latent topic representation of the corpus. However, there is a longstanding assumption that the latent space discovered by these models is generally meaningful and useful, and that evaluating such assumptions is challenging due to its unsupervised training process. Besides, there is a no-gold standard list of topics to compare against every corpus.\n", 23 | "\n", 24 | "Nevertheless, it is equally important to identify if a trained model is objectively good or bad, as well have an ability to compare different models/methods. To do so, one would require an objective measure for the quality. Traditionally, and still for many practical applications, to evaluate if “the correct thing” has been learned about the corpus, an implicit knowledge and “eyeballing” approaches are used. Ideally, we’d like to capture this information in a single metric that can be maximized, and compared.\n", 25 | "\n", 26 | "Let’s take a look at roughly what approaches are commonly used for the evaluation:\n", 27 | "\n", 28 | "**Eye Balling Models**\n", 29 | "- Top N words\n", 30 | "- Topics / Documents\n", 31 | "\n", 32 | "**Intrinsic Evaluation Metrics**\n", 33 | "- Capturing model semantics\n", 34 | "- Topics interpretability\n", 35 | "\n", 36 | "**Human Judgements**\n", 37 | "- What is a topic\n", 38 | "\n", 39 | "**Extrinsic Evaluation Metrics/Evaluation at task**\n", 40 | "- Is model good at performing predefined tasks, such as classification\n", 41 | "\n", 42 | "Natural language is messy, ambiguous and full of subjective interpretation, and sometimes trying to cleanse ambiguity reduces the language to an unnatural form. In this article, we’ll explore more about topic coherence, an intrinsic evaluation metric, and how you can use it to quantitatively justify the model selection.\n", 43 | "\n", 44 | "### What is Topic Coherence?\n", 45 | "\n", 46 | "Before we understand topic coherence, let’s briefly look at the perplexity measure. Perplexity as well is one of the intrinsic evaluation metric, and is widely used for language model evaluation. It captures how surprised a model is of new data it has not seen before, and is measured as the normalized log-likelihood of a held-out test set. \n", 47 | "\n", 48 | "Focussing on the log-likelihood part, you can think of the perplexity metric as measuring how probable some new unseen data is given the model that was learned earlier. That is to say, how well does the model represent or reproduce the statistics of the held-out data.\n", 49 | "\n", 50 | "However, recent studies have shown that predictive likelihood (or equivalently, perplexity) and human judgment are often not correlated, and even sometimes slightly anti-correlated.\n", 51 | "\n", 52 | "*Optimizing for perplexity may not yield human interpretable topics*\n", 53 | "\n", 54 | "This limitation of perplexity measure served as a motivation for more work trying to model the human judgment, and thus *Topic Coherence*.\n", 55 | "\n", 56 | "The concept of topic coherence combines a number of measures into a framework to evaluate the coherence between topics inferred by a model. But before that…\n", 57 | "\n", 58 | "#### What is topic coherence?\n", 59 | "Topic Coherence measures score a single topic by measuring the degree of semantic similarity between high scoring words in the topic. These measurements help distinguish between topics that are semantically interpretable topics and topics that are artifacts of statistical inference. But,\n", 60 | "\n", 61 | "#### What is coherence?\n", 62 | "Topic Coherence measures score a single topic by measuring the degree of semantic similarity between high scoring words in the topic. These measurements help distinguish between topics that are semantically interpretable topics and topics that are artifacts of statistical inference. But …\n", 63 | "\n", 64 | "### Coherence Measures\n", 65 | "Let’s take quick look at different coherence measures, and how they are calculated:\n", 66 | "\n", 67 | "1. `C_v` measure is based on a sliding window, one-set segmentation of the top words and an indirect confirmation measure that uses normalized pointwise mutual information (NPMI) and the cosine similarity\n", 68 | "2. `C_p` is based on a sliding window, one-preceding segmentation of the top words and the confirmation measure of Fitelson's coherence\n", 69 | "3. `C_uci` measure is based on a sliding window and the pointwise mutual information (PMI) of all word pairs of the given top words\n", 70 | "4. `C_umass` is based on document cooccurrence counts, a one-preceding segmentation and a logarithmic conditional probability as confirmation measure\n", 71 | "5. `C_npmi` is an enhanced version of the C_uci coherence using the normalized pointwise mutual information (NPMI)\n", 72 | "6. `C_a` is based on a context window, a pairwise comparison of the top words and an indirect confirmation measure that uses normalized pointwise mutual information (NPMI) and the cosine similarity\n", 73 | "\n", 74 | "There is, of course, a lot more to the concept of topic model evaluation, and the coherence measure. However, keeping in mind the length, and purpose of this article, let’s apply these concepts into developing a model that is at least better than with the default parameters. Also, we’ll be re-purposing already available online pieces of code to support this exercise instead of re-inventing the wheel." 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "### Model Implementation\n", 82 | "1. Loading Data\n", 83 | "2. Data Cleaning\n", 84 | "3. Phrase Modeling: Bi-grams and Tri-grams\n", 85 | "4. Data Transformation: Corpus and Dictionary\n", 86 | "5. Base Model\n", 87 | "6. Hyper-parameter Tuning\n", 88 | "7. Final model\n", 89 | "8. Visualize Results\n", 90 | "\n", 91 | "** **\n", 92 | "\n", 93 | "For this tutorial, we’ll use the dataset of papers published in NeurIPS (NIPS) conference which is one of the most prestigious yearly events in the machine learning community. The CSV data file contains information on the different NeurIPS papers that were published from 1987 until 2016 (29 years!). These papers discuss a wide variety of topics in machine learning, from neural networks to optimization methods, and many more.\n", 94 | "\n", 95 | "\"The\n", 96 | "\n", 97 | "Let’s start by looking at the content of the file\n", 98 | "\n", 99 | "** **\n", 100 | "#### Step 1: Loading Data\n", 101 | "** **\n", 102 | "\n", 103 | "For this tutorial, we’ll use the dataset of papers published in NIPS conference. The NIPS conference (Neural Information Processing Systems) is one of the most prestigious yearly events in the machine learning community. The CSV data file contains information on the different NIPS papers that were published from 1987 until 2016 (29 years!). These papers discuss a wide variety of topics in machine learning, from neural networks to optimization methods, and many more.\n", 104 | "\n", 105 | "Let’s start by looking at the content of the file" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "import zipfile\n", 115 | "import pandas as pd\n", 116 | "import os\n", 117 | "\n", 118 | "# Open the zip file\n", 119 | "with zipfile.ZipFile(\"./data/NIPS Papers.zip\", \"r\") as zip_ref:\n", 120 | " # Extract the file to a temporary directory\n", 121 | " zip_ref.extractall(\"temp\")\n", 122 | "\n", 123 | "# Read the CSV file into a pandas DataFrame\n", 124 | "papers = pd.read_csv(\"temp/NIPS Papers/papers.csv\")\n", 125 | "\n", 126 | "# Print head\n", 127 | "papers.head()" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "** **\n", 135 | "#### Step 2: Data Cleaning\n", 136 | "** **\n", 137 | "\n", 138 | "Since the goal of this analysis is to perform topic modeling, we will solely focus on the text data from each paper, and drop other metadata columns" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [ 147 | "# Remove the columns\n", 148 | "papers = papers.drop(columns=['id', 'title', 'abstract', \n", 149 | " 'event_type', 'pdf_name', 'year'], axis=1)\n", 150 | "\n", 151 | "# sample only 100 papers\n", 152 | "papers = papers.sample(100)\n", 153 | "\n", 154 | "# Print out the first rows of papers\n", 155 | "papers.head()" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "##### Remove punctuation/lower casing\n", 163 | "\n", 164 | "Next, let’s perform a simple preprocessing on the content of paper_text column to make them more amenable for analysis, and reliable results. To do that, we’ll use a regular expression to remove any punctuation, and then lowercase the text" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "metadata": {}, 171 | "outputs": [], 172 | "source": [ 173 | "# Load the regular expression library\n", 174 | "import re\n", 175 | "\n", 176 | "# Remove punctuation\n", 177 | "papers['paper_text_processed'] = papers['paper_text'].map(lambda x: re.sub('[,\\.!?]', '', x))\n", 178 | "\n", 179 | "# Convert the titles to lowercase\n", 180 | "papers['paper_text_processed'] = papers['paper_text_processed'].map(lambda x: x.lower())\n", 181 | "\n", 182 | "# Print out the first rows of papers\n", 183 | "papers['paper_text_processed'].head()" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "##### Tokenize words and further clean-up text\n", 191 | "\n", 192 | "Let’s tokenize each sentence into a list of words, removing punctuations and unnecessary characters altogether." 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "import gensim\n", 202 | "from gensim.utils import simple_preprocess\n", 203 | "\n", 204 | "def sent_to_words(sentences):\n", 205 | " for sentence in sentences:\n", 206 | " yield(gensim.utils.simple_preprocess(str(sentence), deacc=True)) # deacc=True removes punctuations\n", 207 | "\n", 208 | "data = papers.paper_text_processed.values.tolist()\n", 209 | "data_words = list(sent_to_words(data))\n", 210 | "\n", 211 | "print(data_words[:1][0][:30])" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "** **\n", 219 | "#### Step 3: Phrase Modeling: Bigram and Trigram Models\n", 220 | "** **\n", 221 | "\n", 222 | "Bigrams are two words frequently occurring together in the document. Trigrams are 3 words frequently occurring. Some examples in our example are: 'back_bumper', 'oil_leakage', 'maryland_college_park' etc.\n", 223 | "\n", 224 | "Gensim's Phrases model can build and implement the bigrams, trigrams, quadgrams and more. The two important arguments to Phrases are min_count and threshold.\n", 225 | "\n", 226 | "*The higher the values of these param, the harder it is for words to be combined.*" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": null, 232 | "metadata": {}, 233 | "outputs": [], 234 | "source": [ 235 | "# Build the bigram and trigram models\n", 236 | "bigram = gensim.models.Phrases(data_words, min_count=5, threshold=100) # higher threshold fewer phrases.\n", 237 | "trigram = gensim.models.Phrases(bigram[data_words], threshold=100) \n", 238 | "\n", 239 | "# Faster way to get a sentence clubbed as a trigram/bigram\n", 240 | "bigram_mod = gensim.models.phrases.Phraser(bigram)\n", 241 | "trigram_mod = gensim.models.phrases.Phraser(trigram)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "metadata": {}, 247 | "source": [ 248 | "#### Remove Stopwords, Make Bigrams and Lemmatize\n", 249 | "\n", 250 | "The phrase models are ready. Let’s define the functions to remove the stopwords, make trigrams and lemmatization and call them sequentially." 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": null, 256 | "metadata": {}, 257 | "outputs": [], 258 | "source": [ 259 | "# NLTK Stop words\n", 260 | "import nltk\n", 261 | "nltk.download('stopwords')\n", 262 | "from nltk.corpus import stopwords\n", 263 | "\n", 264 | "stop_words = stopwords.words('english')\n", 265 | "stop_words.extend(['from', 'subject', 're', 'edu', 'use'])" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "metadata": {}, 272 | "outputs": [], 273 | "source": [ 274 | "# Define functions for stopwords, bigrams, trigrams and lemmatization\n", 275 | "def remove_stopwords(texts):\n", 276 | " return [[word for word in simple_preprocess(str(doc)) if word not in stop_words] for doc in texts]\n", 277 | "\n", 278 | "def make_bigrams(texts):\n", 279 | " return [bigram_mod[doc] for doc in texts]\n", 280 | "\n", 281 | "def make_trigrams(texts):\n", 282 | " return [trigram_mod[bigram_mod[doc]] for doc in texts]\n", 283 | "\n", 284 | "def lemmatization(texts, allowed_postags=['NOUN', 'ADJ', 'VERB', 'ADV']):\n", 285 | " \"\"\"https://spacy.io/api/annotation\"\"\"\n", 286 | " texts_out = []\n", 287 | " for sent in texts:\n", 288 | " doc = nlp(\" \".join(sent)) \n", 289 | " texts_out.append([token.lemma_ for token in doc if token.pos_ in allowed_postags])\n", 290 | " return texts_out" 291 | ] 292 | }, 293 | { 294 | "cell_type": "markdown", 295 | "metadata": {}, 296 | "source": [ 297 | "Let's call the functions in order." 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": null, 303 | "metadata": {}, 304 | "outputs": [], 305 | "source": [ 306 | "!python -m spacy download en_core_web_sm" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "metadata": {}, 313 | "outputs": [], 314 | "source": [ 315 | "import spacy\n", 316 | "\n", 317 | "# Remove Stop Words\n", 318 | "data_words_nostops = remove_stopwords(data_words)\n", 319 | "\n", 320 | "# Form Bigrams\n", 321 | "data_words_bigrams = make_bigrams(data_words_nostops)\n", 322 | "\n", 323 | "# Initialize spacy 'en' model, keeping only tagger component (for efficiency)\n", 324 | "nlp = spacy.load(\"en_core_web_sm\", disable=['parser', 'ner'])\n", 325 | "\n", 326 | "# Do lemmatization keeping only noun, adj, vb, adv\n", 327 | "data_lemmatized = lemmatization(data_words_bigrams, allowed_postags=['NOUN', 'ADJ', 'VERB', 'ADV'])\n", 328 | "\n", 329 | "print(data_lemmatized[:1][0][:30])" 330 | ] 331 | }, 332 | { 333 | "cell_type": "markdown", 334 | "metadata": {}, 335 | "source": [ 336 | "** **\n", 337 | "#### Step 4: Data transformation: Corpus and Dictionary\n", 338 | "** **\n", 339 | "\n", 340 | "The two main inputs to the LDA topic model are the dictionary(id2word) and the corpus. Let’s create them." 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": null, 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [ 349 | "import gensim.corpora as corpora\n", 350 | "\n", 351 | "# Create Dictionary\n", 352 | "id2word = corpora.Dictionary(data_lemmatized)\n", 353 | "\n", 354 | "# Create Corpus\n", 355 | "texts = data_lemmatized\n", 356 | "\n", 357 | "# Term Document Frequency\n", 358 | "corpus = [id2word.doc2bow(text) for text in texts]\n", 359 | "\n", 360 | "# View\n", 361 | "print(corpus[:1][0][:30])" 362 | ] 363 | }, 364 | { 365 | "cell_type": "markdown", 366 | "metadata": {}, 367 | "source": [ 368 | "** **\n", 369 | "#### Step 5: Base Model \n", 370 | "** **\n", 371 | "\n", 372 | "We have everything required to train the base LDA model. In addition to the corpus and dictionary, you need to provide the number of topics as well. Apart from that, alpha and eta are hyperparameters that affect sparsity of the topics. According to the Gensim docs, both defaults to 1.0/num_topics prior (we'll use default for the base model).\n", 373 | "\n", 374 | "chunksize controls how many documents are processed at a time in the training algorithm. Increasing chunksize will speed up training, at least as long as the chunk of documents easily fit into memory.\n", 375 | "\n", 376 | "passes controls how often we train the model on the entire corpus (set to 10). Another word for passes might be \"epochs\". iterations is somewhat technical, but essentially it controls how often we repeat a particular loop over each document. It is important to set the number of \"passes\" and \"iterations\" high enough." 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [ 385 | "# Build LDA model\n", 386 | "lda_model = gensim.models.LdaMulticore(corpus=corpus,\n", 387 | " id2word=id2word,\n", 388 | " num_topics=10, \n", 389 | " random_state=100,\n", 390 | " chunksize=100,\n", 391 | " passes=10,\n", 392 | " per_word_topics=True)" 393 | ] 394 | }, 395 | { 396 | "cell_type": "markdown", 397 | "metadata": {}, 398 | "source": [ 399 | "** **\n", 400 | "The above LDA model is built with 10 different topics where each topic is a combination of keywords and each keyword contributes a certain weightage to the topic.\n", 401 | "\n", 402 | "You can see the keywords for each topic and the weightage(importance) of each keyword using `lda_model.print_topics()`" 403 | ] 404 | }, 405 | { 406 | "cell_type": "code", 407 | "execution_count": null, 408 | "metadata": {}, 409 | "outputs": [], 410 | "source": [ 411 | "from pprint import pprint\n", 412 | "\n", 413 | "# Print the Keyword in the 10 topics\n", 414 | "pprint(lda_model.print_topics())\n", 415 | "doc_lda = lda_model[corpus]" 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": {}, 421 | "source": [ 422 | "#### Compute Model Perplexity and Coherence Score\n", 423 | "\n", 424 | "Let's calculate the baseline coherence score" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "metadata": {}, 431 | "outputs": [], 432 | "source": [ 433 | "from gensim.models import CoherenceModel\n", 434 | "\n", 435 | "# Compute Coherence Score\n", 436 | "coherence_model_lda = CoherenceModel(model=lda_model, texts=data_lemmatized, dictionary=id2word, coherence='c_v')\n", 437 | "coherence_lda = coherence_model_lda.get_coherence()\n", 438 | "print('Coherence Score: ', coherence_lda)" 439 | ] 440 | }, 441 | { 442 | "cell_type": "markdown", 443 | "metadata": {}, 444 | "source": [ 445 | "** **\n", 446 | "#### Step 6: Hyperparameter tuning\n", 447 | "** **\n", 448 | "First, let's differentiate between model hyperparameters and model parameters :\n", 449 | "\n", 450 | "- `Model hyperparameters` can be thought of as settings for a machine learning algorithm that are tuned by the data scientist before training. Examples would be the number of trees in the random forest, or in our case, number of topics K\n", 451 | "\n", 452 | "- `Model parameters` can be thought of as what the model learns during training, such as the weights for each word in a given topic.\n", 453 | "\n", 454 | "Now that we have the baseline coherence score for the default LDA model, let's perform a series of sensitivity tests to help determine the following model hyperparameters: \n", 455 | "- Number of Topics (K)\n", 456 | "- Dirichlet hyperparameter alpha: Document-Topic Density\n", 457 | "- Dirichlet hyperparameter beta: Word-Topic Density\n", 458 | "\n", 459 | "We'll perform these tests in sequence, one parameter at a time by keeping others constant and run them over the two difference validation corpus sets. We'll use `C_v` as our choice of metric for performance comparison " 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": null, 465 | "metadata": {}, 466 | "outputs": [], 467 | "source": [ 468 | "# supporting function\n", 469 | "def compute_coherence_values(corpus, dictionary, k, a, b):\n", 470 | " \n", 471 | " lda_model = gensim.models.LdaMulticore(corpus=corpus,\n", 472 | " id2word=dictionary,\n", 473 | " num_topics=k, \n", 474 | " random_state=100,\n", 475 | " chunksize=100,\n", 476 | " passes=10,\n", 477 | " alpha=a,\n", 478 | " eta=b)\n", 479 | " \n", 480 | " coherence_model_lda = CoherenceModel(model=lda_model, texts=data_lemmatized, dictionary=id2word, coherence='c_v')\n", 481 | " \n", 482 | " return coherence_model_lda.get_coherence()" 483 | ] 484 | }, 485 | { 486 | "cell_type": "markdown", 487 | "metadata": {}, 488 | "source": [ 489 | "Let's call the function, and iterate it over the range of topics, alpha, and beta parameter values" 490 | ] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": null, 495 | "metadata": {}, 496 | "outputs": [], 497 | "source": [ 498 | "import numpy as np\n", 499 | "import tqdm\n", 500 | "\n", 501 | "grid = {}\n", 502 | "grid['Validation_Set'] = {}\n", 503 | "\n", 504 | "# Topics range\n", 505 | "min_topics = 2\n", 506 | "max_topics = 11\n", 507 | "step_size = 1\n", 508 | "topics_range = range(min_topics, max_topics, step_size)\n", 509 | "\n", 510 | "# Alpha parameter\n", 511 | "alpha = list(np.arange(0.01, 1, 0.3))\n", 512 | "alpha.append('symmetric')\n", 513 | "alpha.append('asymmetric')\n", 514 | "\n", 515 | "# Beta parameter\n", 516 | "beta = list(np.arange(0.01, 1, 0.3))\n", 517 | "beta.append('symmetric')\n", 518 | "\n", 519 | "# Validation sets\n", 520 | "num_of_docs = len(corpus)\n", 521 | "corpus_sets = [gensim.utils.ClippedCorpus(corpus, int(num_of_docs*0.75)), \n", 522 | " corpus]\n", 523 | "\n", 524 | "corpus_title = ['75% Corpus', '100% Corpus']\n", 525 | "\n", 526 | "model_results = {'Validation_Set': [],\n", 527 | " 'Topics': [],\n", 528 | " 'Alpha': [],\n", 529 | " 'Beta': [],\n", 530 | " 'Coherence': []\n", 531 | " }\n", 532 | "\n", 533 | "# Can take a long time to run\n", 534 | "if 1 == 1:\n", 535 | " pbar = tqdm.tqdm(total=(len(beta)*len(alpha)*len(topics_range)*len(corpus_title)))\n", 536 | " \n", 537 | " # iterate through validation corpuses\n", 538 | " for i in range(len(corpus_sets)):\n", 539 | " # iterate through number of topics\n", 540 | " for k in topics_range:\n", 541 | " # iterate through alpha values\n", 542 | " for a in alpha:\n", 543 | " # iterare through beta values\n", 544 | " for b in beta:\n", 545 | " # get the coherence score for the given parameters\n", 546 | " cv = compute_coherence_values(corpus=corpus_sets[i], dictionary=id2word, \n", 547 | " k=k, a=a, b=b)\n", 548 | " # Save the model results\n", 549 | " model_results['Validation_Set'].append(corpus_title[i])\n", 550 | " model_results['Topics'].append(k)\n", 551 | " model_results['Alpha'].append(a)\n", 552 | " model_results['Beta'].append(b)\n", 553 | " model_results['Coherence'].append(cv)\n", 554 | " \n", 555 | " pbar.update(1)\n", 556 | " pd.DataFrame(model_results).to_csv('./results/lda_tuning_results.csv', index=False)\n", 557 | " pbar.close()" 558 | ] 559 | }, 560 | { 561 | "cell_type": "markdown", 562 | "metadata": {}, 563 | "source": [ 564 | "** **\n", 565 | "#### Step 7: Final Model\n", 566 | "** **\n", 567 | "\n", 568 | "Based on external evaluation (Code to be added from Excel based analysis), let's train the final model with parameters yielding highest coherence score" 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": null, 574 | "metadata": {}, 575 | "outputs": [], 576 | "source": [ 577 | "num_topics = 8\n", 578 | "\n", 579 | "lda_model = gensim.models.LdaMulticore(corpus=corpus,\n", 580 | " id2word=id2word,\n", 581 | " num_topics=num_topics, \n", 582 | " random_state=100,\n", 583 | " chunksize=100,\n", 584 | " passes=10,\n", 585 | " alpha=0.01,\n", 586 | " eta=0.9)" 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": null, 592 | "metadata": {}, 593 | "outputs": [], 594 | "source": [ 595 | "from pprint import pprint\n", 596 | "\n", 597 | "# Print the Keyword in the 10 topics\n", 598 | "pprint(lda_model.print_topics())\n", 599 | "doc_lda = lda_model[corpus]" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "metadata": {}, 605 | "source": [ 606 | "** **\n", 607 | "#### Step 8: Visualize Results\n", 608 | "** **" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": null, 614 | "metadata": {}, 615 | "outputs": [], 616 | "source": [ 617 | "import pyLDAvis.gensim_models as gensimvis\n", 618 | "import pickle \n", 619 | "import pyLDAvis\n", 620 | "\n", 621 | "# Visualize the topics\n", 622 | "pyLDAvis.enable_notebook()\n", 623 | "\n", 624 | "LDAvis_data_filepath = os.path.join('./results/ldavis_tuned_'+str(num_topics))\n", 625 | "\n", 626 | "# # this is a bit time consuming - make the if statement True\n", 627 | "# # if you want to execute visualization prep yourself\n", 628 | "if 1 == 1:\n", 629 | " LDAvis_prepared = gensimvis.prepare(lda_model, corpus, id2word)\n", 630 | " with open(LDAvis_data_filepath, 'wb') as f:\n", 631 | " pickle.dump(LDAvis_prepared, f)\n", 632 | "\n", 633 | "# load the pre-prepared pyLDAvis data from disk\n", 634 | "with open(LDAvis_data_filepath, 'rb') as f:\n", 635 | " LDAvis_prepared = pickle.load(f)\n", 636 | "\n", 637 | "pyLDAvis.save_html(LDAvis_prepared, './results/ldavis_tuned_'+ str(num_topics) +'.html')\n", 638 | "\n", 639 | "LDAvis_prepared" 640 | ] 641 | }, 642 | { 643 | "cell_type": "markdown", 644 | "metadata": {}, 645 | "source": [ 646 | "** **\n", 647 | "#### Closing Notes\n", 648 | "\n", 649 | "We started with understanding why evaluating the topic model is essential. Next, we reviewed existing methods and scratched the surface of topic coherence, along with the available coherence measures. Then we built a default LDA model using Gensim implementation to establish the baseline coherence score and reviewed practical ways to optimize the LDA hyperparameters.\n", 650 | "\n", 651 | "Hopefully, this article has managed to shed light on the underlying topic evaluation strategies, and intuitions behind it.\n", 652 | "\n", 653 | "** **\n", 654 | "#### References:\n", 655 | "1. http://qpleple.com/perplexity-to-evaluate-topic-models/\n", 656 | "2. https://www.amazon.com/Machine-Learning-Probabilistic-Perspective-Computation/dp/0262018020\n", 657 | "3. https://papers.nips.cc/paper/3700-reading-tea-leaves-how-humans-interpret-topic-models.pdf\n", 658 | "4. https://github.com/mattilyra/pydataberlin-2017/blob/master/notebook/EvaluatingUnsupervisedModels.ipynb\n", 659 | "5. https://www.machinelearningplus.com/nlp/topic-modeling-gensim-python/\n", 660 | "6. http://svn.aksw.org/papers/2015/WSDM_Topic_Evaluation/public.pdf\n", 661 | "7. http://palmetto.aksw.org/palmetto-webapp/" 662 | ] 663 | } 664 | ], 665 | "metadata": { 666 | "kernelspec": { 667 | "display_name": "Python 3 (ipykernel)", 668 | "language": "python", 669 | "name": "python3" 670 | }, 671 | "language_info": { 672 | "codemirror_mode": { 673 | "name": "ipython", 674 | "version": 3 675 | }, 676 | "file_extension": ".py", 677 | "mimetype": "text/x-python", 678 | "name": "python", 679 | "nbconvert_exporter": "python", 680 | "pygments_lexer": "ipython3", 681 | "version": "3.9.16" 682 | } 683 | }, 684 | "nbformat": 4, 685 | "nbformat_minor": 4 686 | } 687 | -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/Introduction to Topic Modeling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Introduction\n", 8 | "##### How to get started with topic modeling using LDA in Python\n", 9 | "** **\n", 10 | "Topic Models, in a nutshell, are a type of statistical language models used for uncovering hidden structure in a collection of texts. In a practical and more intuitively, you can think of it as a task of:\n", 11 | "\n", 12 | "- **Dimensionality Reduction**, where rather than representing a text T in its feature space as {Word_i: count(Word_i, T) for Word_i in Vocabulary}, you can represent it in a topic space as {Topic_i: Weight(Topic_i, T) for Topic_i in Topics}\n", 13 | "- **Unsupervised Learning**, where it can be compared to clustering, as in the case of clustering, the number of topics, like the number of clusters, is an output parameter. By doing topic modeling, we build clusters of words rather than clusters of texts. A text is thus a mixture of all the topics, each having a specific weight\n", 14 | "- **Tagging**, abstract “topics” that occur in a collection of documents that best represents the information in them.\n", 15 | "\n", 16 | "There are several existing algorithms you can use to perform the topic modeling. The most common of it are, Latent Semantic Analysis (LSA/LSI), Probabilistic Latent Semantic Analysis (pLSA), and Latent Dirichlet Allocation (LDA)\n", 17 | "\n", 18 | "In this tutorial, we’ll take a closer look at LDA, and implement our first topic model using the sklearn implementation in python 2.7\n", 19 | "\n", 20 | "### Theoretical Overview\n", 21 | "LDA is a generative probabilistic model that assumes each topic is a mixture over an underlying set of words, and each document is a mixture of over a set of topic probabilities.\n", 22 | "\n", 23 | "![LDA_Model](https://github.com/chdoig/pytexas2015-topic-modeling/blob/master/images/lda-4.png?raw=true)\n", 24 | "\n", 25 | "We can describe the generative process of LDA as, given the M number of documents, N number of words, and prior K number of topics, the model trains to output:\n", 26 | "\n", 27 | "- `psi`, the distribution of words for each topic K\n", 28 | "- `phi`, the distribution of topics for each document i\n", 29 | "\n", 30 | "#### Parameters of LDA\n", 31 | "\n", 32 | "- `Alpha parameter` is Dirichlet prior concentration parameter that represents document-topic density — with a higher alpha, documents are assumed to be made up of more topics and result in more specific topic distribution per document.\n", 33 | "- `Beta parameter` is the same prior concentration parameter that represents topic-word density — with high beta, topics are assumed to made of up most of the words and result in a more specific word distribution per topic.\n", 34 | "\n", 35 | "**To read more: https://towardsdatascience.com/end-to-end-topic-modeling-in-python-latent-dirichlet-allocation-lda-35ce4ed6b3e0**" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "** **\n", 43 | "### LDA Implementation\n", 44 | "\n", 45 | "1. [Loading data](#load_data)\n", 46 | "2. [Data cleaning](#clean_data)\n", 47 | "3. [Exploratory analysis](#eda)\n", 48 | "4. [Prepare data for LDA analysis](#data_preparation)\n", 49 | "5. [LDA model training](#train_model)\n", 50 | "6. [Analyzing LDA model results](#results)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "** **\n", 58 | "For this tutorial, we’ll use the dataset of papers published in NeurIPS (NIPS) conference which is one of the most prestigious yearly events in the machine learning community. The CSV data file contains information on the different NeurIPS papers that were published from 1987 until 2016 (29 years!). These papers discuss a wide variety of topics in machine learning, from neural networks to optimization methods, and many more.\n", 59 | "\n", 60 | "\"The\n", 61 | "\n", 62 | "Let’s start by looking at the content of the file" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "** **\n", 70 | "#### Step 1: Loading Data \n", 71 | "** **\n", 72 | "For this tutorial, we’ll use the dataset of papers published in NeurIPS (NIPS) conference which is one of the most prestigious yearly events in the machine learning community. The CSV data file contains information on the different NeurIPS papers that were published from 1987 until 2016 (29 years!). These papers discuss a wide variety of topics in machine learning, from neural networks to optimization methods, and many more.\n", 73 | "\n", 74 | "Let’s start by looking at the content of the file" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "import zipfile\n", 84 | "import pandas as pd\n", 85 | "import os\n", 86 | "\n", 87 | "# Open the zip file\n", 88 | "with zipfile.ZipFile(\"./data/NIPS Papers.zip\", \"r\") as zip_ref:\n", 89 | " # Extract the file to a temporary directory\n", 90 | " zip_ref.extractall(\"temp\")\n", 91 | "\n", 92 | "# Read the CSV file into a pandas DataFrame\n", 93 | "papers = pd.read_csv(\"temp/NIPS Papers/papers.csv\")\n", 94 | "\n", 95 | "# Print head\n", 96 | "papers.head()" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "** **\n", 104 | "#### Step 2: Data Cleaning \n", 105 | "** **\n", 106 | "\n", 107 | "Since the goal of this analysis is to perform topic modeling, let's focus only on the text data from each paper, and drop other metadata columns. Also, for the demonstration, we'll only look at 100 papers" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "# Remove the columns\n", 117 | "papers = papers.drop(columns=['id', 'event_type', 'pdf_name'], axis=1).sample(100)\n", 118 | "\n", 119 | "# Print out the first rows of papers\n", 120 | "papers.head()" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "##### Remove punctuation/lower casing\n", 128 | "\n", 129 | "Next, let’s perform a simple preprocessing on the content of `paper_text` column to make them more amenable for analysis, and reliable results. To do that, we’ll use a regular expression to remove any punctuation, and then lowercase the text" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "# Load the regular expression library\n", 139 | "import re\n", 140 | "\n", 141 | "# Remove punctuation\n", 142 | "papers['paper_text_processed'] = \\\n", 143 | "papers['paper_text'].map(lambda x: re.sub('[,\\.!?]', '', x))\n", 144 | "\n", 145 | "# Convert the titles to lowercase\n", 146 | "papers['paper_text_processed'] = \\\n", 147 | "papers['paper_text_processed'].map(lambda x: x.lower())\n", 148 | "\n", 149 | "# Print out the first rows of papers\n", 150 | "papers['paper_text_processed'].head()" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "** **\n", 158 | "#### Step 3: Exploratory Analysis \n", 159 | "** **\n", 160 | "\n", 161 | "To verify whether the preprocessing, we’ll make a simple word cloud using the `wordcloud` package to get a visual representation of most common words. It is key to understanding the data and ensuring we are on the right track, and if any more preprocessing is necessary before training the model." 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [ 170 | "# Import the wordcloud library\n", 171 | "from wordcloud import WordCloud\n", 172 | "\n", 173 | "# Join the different processed titles together.\n", 174 | "long_string = ','.join(list(papers['paper_text_processed'].values))\n", 175 | "\n", 176 | "# Create a WordCloud object\n", 177 | "wordcloud = WordCloud(background_color=\"white\", max_words=1000, contour_width=3, contour_color='steelblue')\n", 178 | "\n", 179 | "# Generate a word cloud\n", 180 | "wordcloud.generate(long_string)\n", 181 | "\n", 182 | "# Visualize the word cloud\n", 183 | "wordcloud.to_image()" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "** **\n", 191 | "#### Step 4: Prepare text for LDA analysis \n", 192 | "** **\n", 193 | "\n", 194 | "Next, let’s work to transform the textual data in a format that will serve as an input for training LDA model. We start by tokenizing the text and removing stopwords. Next, we convert the tokenized object into a corpus and dictionary." 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": null, 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [ 203 | "import gensim\n", 204 | "from gensim.utils import simple_preprocess\n", 205 | "import nltk\n", 206 | "nltk.download('stopwords')\n", 207 | "from nltk.corpus import stopwords\n", 208 | "\n", 209 | "stop_words = stopwords.words('english')\n", 210 | "stop_words.extend(['from', 'subject', 're', 'edu', 'use'])\n", 211 | "\n", 212 | "def sent_to_words(sentences):\n", 213 | " for sentence in sentences:\n", 214 | " # deacc=True removes punctuations\n", 215 | " yield(gensim.utils.simple_preprocess(str(sentence), deacc=True))\n", 216 | "\n", 217 | "def remove_stopwords(texts):\n", 218 | " return [[word for word in simple_preprocess(str(doc)) \n", 219 | " if word not in stop_words] for doc in texts]\n", 220 | "\n", 221 | "\n", 222 | "data = papers.paper_text_processed.values.tolist()\n", 223 | "data_words = list(sent_to_words(data))\n", 224 | "\n", 225 | "# remove stop words\n", 226 | "data_words = remove_stopwords(data_words)\n", 227 | "\n", 228 | "print(data_words[:1][0][:30])" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": null, 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "import gensim.corpora as corpora\n", 238 | "\n", 239 | "# Create Dictionary\n", 240 | "id2word = corpora.Dictionary(data_words)\n", 241 | "\n", 242 | "# Create Corpus\n", 243 | "texts = data_words\n", 244 | "\n", 245 | "# Term Document Frequency\n", 246 | "corpus = [id2word.doc2bow(text) for text in texts]\n", 247 | "\n", 248 | "# View\n", 249 | "print(corpus[:1][0][:30])" 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "metadata": {}, 255 | "source": [ 256 | "** **\n", 257 | "#### Step 5: LDA model tranining \n", 258 | "** **\n", 259 | "\n", 260 | "To keep things simple, we'll keep all the parameters to default except for inputting the number of topics. For this tutorial, we will build a model with 10 topics where each topic is a combination of keywords, and each keyword contributes a certain weightage to the topic." 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": {}, 267 | "outputs": [], 268 | "source": [ 269 | "from pprint import pprint\n", 270 | "\n", 271 | "# number of topics\n", 272 | "num_topics = 10\n", 273 | "\n", 274 | "# Build LDA model\n", 275 | "lda_model = gensim.models.LdaMulticore(corpus=corpus,\n", 276 | " id2word=id2word,\n", 277 | " num_topics=num_topics)\n", 278 | "\n", 279 | "# Print the Keyword in the 10 topics\n", 280 | "pprint(lda_model.print_topics())\n", 281 | "doc_lda = lda_model[corpus]" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": {}, 287 | "source": [ 288 | "** **\n", 289 | "#### Step 6: Analyzing our LDA model \n", 290 | "** **\n", 291 | "\n", 292 | "Now that we have a trained model let’s visualize the topics for interpretability. To do so, we’ll use a popular visualization package, pyLDAvis which is designed to help interactively with:\n", 293 | "\n", 294 | "1. Better understanding and interpreting individual topics, and\n", 295 | "2. Better understanding the relationships between the topics.\n", 296 | "\n", 297 | "For (1), you can manually select each topic to view its top most frequent and/or “relevant” terms, using different values of the λ parameter. This can help when you’re trying to assign a human interpretable name or “meaning” to each topic.\n", 298 | "\n", 299 | "For (2), exploring the Intertopic Distance Plot can help you learn about how topics relate to each other, including potential higher-level structure between groups of topics." 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": null, 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [ 308 | "import pyLDAvis.gensim_models as gensimvis\n", 309 | "import pickle \n", 310 | "import pyLDAvis\n", 311 | "\n", 312 | "# Visualize the topics\n", 313 | "pyLDAvis.enable_notebook()\n", 314 | "\n", 315 | "LDAvis_data_filepath = os.path.join('./results/ldavis_prepared_'+str(num_topics))\n", 316 | "\n", 317 | "# # this is a bit time consuming - make the if statement True\n", 318 | "# # if you want to execute visualization prep yourself\n", 319 | "if 1 == 1:\n", 320 | " LDAvis_prepared = gensimvis.prepare(lda_model, corpus, id2word)\n", 321 | " with open(LDAvis_data_filepath, 'wb') as f:\n", 322 | " pickle.dump(LDAvis_prepared, f)\n", 323 | "\n", 324 | "# load the pre-prepared pyLDAvis data from disk\n", 325 | "with open(LDAvis_data_filepath, 'rb') as f:\n", 326 | " LDAvis_prepared = pickle.load(f)\n", 327 | "\n", 328 | "pyLDAvis.save_html(LDAvis_prepared, './results/ldavis_prepared_'+ str(num_topics) +'.html')\n", 329 | "\n", 330 | "LDAvis_prepared" 331 | ] 332 | }, 333 | { 334 | "cell_type": "markdown", 335 | "metadata": {}, 336 | "source": [ 337 | "** **\n", 338 | "#### Closing Notes\n", 339 | "Machine learning has become increasingly popular over the past decade, and recent advances in computational availability have led to exponential growth to people looking for ways how new methods can be incorporated to advance the field of Natural Language Processing.\n", 340 | "\n", 341 | "Often, we treat topic models as black-box algorithms, but hopefully, this article addressed to shed light on the underlying math, and intuitions behind it, and high-level code to get you started with any textual data.\n", 342 | "\n", 343 | "In the next article, we’ll go one step deeper into understanding how you can evaluate the performance of topic models, tune its hyper-parameters to get more intuitive and reliable results.\n", 344 | "\n", 345 | "** **\n", 346 | "#### References:\n", 347 | "1. Topic model — Wikipedia. https://en.wikipedia.org/wiki/Topic_model\n", 348 | "2. Distributed Strategies for Topic Modeling. https://www.ideals.illinois.edu/bitstream/handle/2142/46405/ParallelTopicModels.pdf?sequence=2&isAllowed=y\n", 349 | "3. Topic Mapping — Software — Resources — Amaral Lab. https://amaral.northwestern.edu/resources/software/topic-mapping\n", 350 | "4. A Survey of Topic Modeling in Text Mining. https://thesai.org/Downloads/Volume6No1/Paper_21-A_Survey_of_Topic_Modeling_in_Text_Mining.pdf\n" 351 | ] 352 | } 353 | ], 354 | "metadata": { 355 | "kernelspec": { 356 | "display_name": "Python 3 (ipykernel)", 357 | "language": "python", 358 | "name": "python3" 359 | }, 360 | "language_info": { 361 | "codemirror_mode": { 362 | "name": "ipython", 363 | "version": 3 364 | }, 365 | "file_extension": ".py", 366 | "mimetype": "text/x-python", 367 | "name": "python", 368 | "nbconvert_exporter": "python", 369 | "pygments_lexer": "ipython3", 370 | "version": "3.9.16" 371 | } 372 | }, 373 | "nbformat": 4, 374 | "nbformat_minor": 4 375 | } 376 | -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/data/NIPS Papers.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/topic-modeling/data/NIPS Papers.zip -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "topic-modeling" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Shashank Kapadia "] 6 | readme = "README.md" 7 | packages = [{include = "topic_modeling"}] 8 | 9 | [tool.poetry.dependencies] 10 | python = ">=3.9,<3.10" 11 | jupyterlab = "^3.5.2" 12 | pandas = "^1.5.2" 13 | gensim = "^4.3.0" 14 | nltk = "^3.8" 15 | spacy = "^3.4.4" 16 | tqdm = "^4.64.1" 17 | pyldavis = "^3.3.1" 18 | wordcloud = "^1.8.2.2" 19 | 20 | 21 | [build-system] 22 | requires = ["poetry-core"] 23 | build-backend = "poetry.core.masonry.api" 24 | -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/results/lda_tuning_results.csv: -------------------------------------------------------------------------------- 1 | Validation_Set,Topics,Alpha,Beta,Coherence 2 | 75% Corpus,2,0.01,0.01,0.25978135607988706 3 | 75% Corpus,2,0.01,0.31,0.2668476722607104 4 | 75% Corpus,2,0.01,0.61,0.2776409400108895 5 | 75% Corpus,2,0.01,0.9099999999999999,0.2716233211418745 6 | 75% Corpus,2,0.01,symmetric,0.27332996032921053 7 | 75% Corpus,2,0.31,0.01,0.25978135607988706 8 | 75% Corpus,2,0.31,0.31,0.2668476722607104 9 | 75% Corpus,2,0.31,0.61,0.2776409400108895 10 | 75% Corpus,2,0.31,0.9099999999999999,0.2716233211418745 11 | 75% Corpus,2,0.31,symmetric,0.27332996032921053 12 | 75% Corpus,2,0.61,0.01,0.25978135607988706 13 | 75% Corpus,2,0.61,0.31,0.2668476722607104 14 | 75% Corpus,2,0.61,0.61,0.2776409400108895 15 | 75% Corpus,2,0.61,0.9099999999999999,0.2716233211418745 16 | 75% Corpus,2,0.61,symmetric,0.27332996032921053 17 | 75% Corpus,2,0.9099999999999999,0.01,0.25978135607988706 18 | 75% Corpus,2,0.9099999999999999,0.31,0.2668476722607104 19 | 75% Corpus,2,0.9099999999999999,0.61,0.27764094001088946 20 | 75% Corpus,2,0.9099999999999999,0.9099999999999999,0.2766757371950356 21 | 75% Corpus,2,0.9099999999999999,symmetric,0.27332996032921053 22 | 75% Corpus,2,symmetric,0.01,0.25978135607988706 23 | 75% Corpus,2,symmetric,0.31,0.2668476722607104 24 | 75% Corpus,2,symmetric,0.61,0.2776409400108895 25 | 75% Corpus,2,symmetric,0.9099999999999999,0.2716233211418745 26 | 75% Corpus,2,symmetric,symmetric,0.27332996032921053 27 | 75% Corpus,2,asymmetric,0.01,0.25978135607988706 28 | 75% Corpus,2,asymmetric,0.31,0.2668476722607104 29 | 75% Corpus,2,asymmetric,0.61,0.27764094001088957 30 | 75% Corpus,2,asymmetric,0.9099999999999999,0.27162332114187443 31 | 75% Corpus,2,asymmetric,symmetric,0.27332996032921053 32 | 75% Corpus,3,0.01,0.01,0.27839627006352724 33 | 75% Corpus,3,0.01,0.31,0.2714832672445246 34 | 75% Corpus,3,0.01,0.61,0.27129619317484943 35 | 75% Corpus,3,0.01,0.9099999999999999,0.26967265698428594 36 | 75% Corpus,3,0.01,symmetric,0.2710418286483521 37 | 75% Corpus,3,0.31,0.01,0.27839627006352724 38 | 75% Corpus,3,0.31,0.31,0.2714832672445246 39 | 75% Corpus,3,0.31,0.61,0.27129619317484943 40 | 75% Corpus,3,0.31,0.9099999999999999,0.26967265698428594 41 | 75% Corpus,3,0.31,symmetric,0.2741049024792329 42 | 75% Corpus,3,0.61,0.01,0.27839627006352724 43 | 75% Corpus,3,0.61,0.31,0.27351453271228904 44 | 75% Corpus,3,0.61,0.61,0.2730873971333492 45 | 75% Corpus,3,0.61,0.9099999999999999,0.26967265698428594 46 | 75% Corpus,3,0.61,symmetric,0.27410490247923297 47 | 75% Corpus,3,0.9099999999999999,0.01,0.27839627006352724 48 | 75% Corpus,3,0.9099999999999999,0.31,0.27351453271228904 49 | 75% Corpus,3,0.9099999999999999,0.61,0.2766291342273802 50 | 75% Corpus,3,0.9099999999999999,0.9099999999999999,0.26645454631910853 51 | 75% Corpus,3,0.9099999999999999,symmetric,0.2714832672445246 52 | 75% Corpus,3,symmetric,0.01,0.27839627006352724 53 | 75% Corpus,3,symmetric,0.31,0.2714832672445246 54 | 75% Corpus,3,symmetric,0.61,0.27129619317484943 55 | 75% Corpus,3,symmetric,0.9099999999999999,0.26967265698428594 56 | 75% Corpus,3,symmetric,symmetric,0.27410490247923297 57 | 75% Corpus,3,asymmetric,0.01,0.27839627006352724 58 | 75% Corpus,3,asymmetric,0.31,0.2761361679469974 59 | 75% Corpus,3,asymmetric,0.61,0.27335893705876174 60 | 75% Corpus,3,asymmetric,0.9099999999999999,0.2679744346749598 61 | 75% Corpus,3,asymmetric,symmetric,0.27410490247923297 62 | 75% Corpus,4,0.01,0.01,0.2668910500383095 63 | 75% Corpus,4,0.01,0.31,0.2838954443896148 64 | 75% Corpus,4,0.01,0.61,0.2865926544014952 65 | 75% Corpus,4,0.01,0.9099999999999999,0.27003887281216177 66 | 75% Corpus,4,0.01,symmetric,0.2796510251967742 67 | 75% Corpus,4,0.31,0.01,0.2668910500383095 68 | 75% Corpus,4,0.31,0.31,0.2838954443896148 69 | 75% Corpus,4,0.31,0.61,0.2865926544014952 70 | 75% Corpus,4,0.31,0.9099999999999999,0.2725567640010955 71 | 75% Corpus,4,0.31,symmetric,0.2806724093952981 72 | 75% Corpus,4,0.61,0.01,0.2668910500383095 73 | 75% Corpus,4,0.61,0.31,0.28505646918509386 74 | 75% Corpus,4,0.61,0.61,0.2892439806686463 75 | 75% Corpus,4,0.61,0.9099999999999999,0.2725567640010955 76 | 75% Corpus,4,0.61,symmetric,0.2806724093952981 77 | 75% Corpus,4,0.9099999999999999,0.01,0.2685576018605267 78 | 75% Corpus,4,0.9099999999999999,0.31,0.2860778533836178 79 | 75% Corpus,4,0.9099999999999999,0.61,0.2892439806686463 80 | 75% Corpus,4,0.9099999999999999,0.9099999999999999,0.2725567640010955 81 | 75% Corpus,4,0.9099999999999999,symmetric,0.27955372987186383 82 | 75% Corpus,4,symmetric,0.01,0.2668910500383095 83 | 75% Corpus,4,symmetric,0.31,0.2838954443896148 84 | 75% Corpus,4,symmetric,0.61,0.2865926544014952 85 | 75% Corpus,4,symmetric,0.9099999999999999,0.2725567640010955 86 | 75% Corpus,4,symmetric,symmetric,0.2806724093952981 87 | 75% Corpus,4,asymmetric,0.01,0.26812725545164134 88 | 75% Corpus,4,asymmetric,0.31,0.2838954443896148 89 | 75% Corpus,4,asymmetric,0.61,0.29144326581678964 90 | 75% Corpus,4,asymmetric,0.9099999999999999,0.2721780507981776 91 | 75% Corpus,4,asymmetric,symmetric,0.27675604929105146 92 | 75% Corpus,5,0.01,0.01,0.2921917497600287 93 | 75% Corpus,5,0.01,0.31,0.27552154453031585 94 | 75% Corpus,5,0.01,0.61,0.269308750481684 95 | 75% Corpus,5,0.01,0.9099999999999999,0.2709825760478901 96 | 75% Corpus,5,0.01,symmetric,0.2748624070876895 97 | 75% Corpus,5,0.31,0.01,0.2921917497600287 98 | 75% Corpus,5,0.31,0.31,0.2748594189290374 99 | 75% Corpus,5,0.31,0.61,0.27297615024851607 100 | 75% Corpus,5,0.31,0.9099999999999999,0.27487775415711974 101 | 75% Corpus,5,0.31,symmetric,0.27717279279720247 102 | 75% Corpus,5,0.61,0.01,0.29578845568370865 103 | 75% Corpus,5,0.61,0.31,0.27395015677623524 104 | 75% Corpus,5,0.61,0.61,0.27297615024851607 105 | 75% Corpus,5,0.61,0.9099999999999999,0.2740301275419981 106 | 75% Corpus,5,0.61,symmetric,0.2771727927972025 107 | 75% Corpus,5,0.9099999999999999,0.01,0.2957884556837086 108 | 75% Corpus,5,0.9099999999999999,0.31,0.27395015677623524 109 | 75% Corpus,5,0.9099999999999999,0.61,0.28404895953113735 110 | 75% Corpus,5,0.9099999999999999,0.9099999999999999,0.277640513968081 111 | 75% Corpus,5,0.9099999999999999,symmetric,0.27934536161569634 112 | 75% Corpus,5,symmetric,0.01,0.2921917497600287 113 | 75% Corpus,5,symmetric,0.31,0.2748594189290374 114 | 75% Corpus,5,symmetric,0.61,0.2689322892718954 115 | 75% Corpus,5,symmetric,0.9099999999999999,0.27487775415711974 116 | 75% Corpus,5,symmetric,symmetric,0.2748624070876895 117 | 75% Corpus,5,asymmetric,0.01,0.29578845568370865 118 | 75% Corpus,5,asymmetric,0.31,0.2757452278352188 119 | 75% Corpus,5,asymmetric,0.61,0.26239407325290853 120 | 75% Corpus,5,asymmetric,0.9099999999999999,0.2686874093590562 121 | 75% Corpus,5,asymmetric,symmetric,0.2770349759061833 122 | 75% Corpus,6,0.01,0.01,0.30284473516050225 123 | 75% Corpus,6,0.01,0.31,0.30249950909918444 124 | 75% Corpus,6,0.01,0.61,0.3121782769555992 125 | 75% Corpus,6,0.01,0.9099999999999999,0.35411824844325124 126 | 75% Corpus,6,0.01,symmetric,0.30436985837998276 127 | 75% Corpus,6,0.31,0.01,0.301390971353645 128 | 75% Corpus,6,0.31,0.31,0.3024063840590527 129 | 75% Corpus,6,0.31,0.61,0.31042451210080446 130 | 75% Corpus,6,0.31,0.9099999999999999,0.35411824844325124 131 | 75% Corpus,6,0.31,symmetric,0.30491985962114915 132 | 75% Corpus,6,0.61,0.01,0.30064456740988804 133 | 75% Corpus,6,0.61,0.31,0.30715638376430365 134 | 75% Corpus,6,0.61,0.61,0.31042451210080446 135 | 75% Corpus,6,0.61,0.9099999999999999,0.35418725691606756 136 | 75% Corpus,6,0.61,symmetric,0.3049198596211492 137 | 75% Corpus,6,0.9099999999999999,0.01,0.3013337842863722 138 | 75% Corpus,6,0.9099999999999999,0.31,0.3024679491620339 139 | 75% Corpus,6,0.9099999999999999,0.61,0.31042451210080446 140 | 75% Corpus,6,0.9099999999999999,0.9099999999999999,0.3541872569160675 141 | 75% Corpus,6,0.9099999999999999,symmetric,0.30491985962114915 142 | 75% Corpus,6,symmetric,0.01,0.30065930794388435 143 | 75% Corpus,6,symmetric,0.31,0.3024063840590527 144 | 75% Corpus,6,symmetric,0.61,0.31042451210080446 145 | 75% Corpus,6,symmetric,0.9099999999999999,0.35411824844325124 146 | 75% Corpus,6,symmetric,symmetric,0.30436985837998276 147 | 75% Corpus,6,asymmetric,0.01,0.2967291360253754 148 | 75% Corpus,6,asymmetric,0.31,0.302076431936051 149 | 75% Corpus,6,asymmetric,0.61,0.30847841491074096 150 | 75% Corpus,6,asymmetric,0.9099999999999999,0.35477042247541973 151 | 75% Corpus,6,asymmetric,symmetric,0.3073932906534706 152 | 75% Corpus,7,0.01,0.01,0.2811852190841381 153 | 75% Corpus,7,0.01,0.31,0.2920220131136521 154 | 75% Corpus,7,0.01,0.61,0.28852068336946435 155 | 75% Corpus,7,0.01,0.9099999999999999,0.316288019095773 156 | 75% Corpus,7,0.01,symmetric,0.2726152139083012 157 | 75% Corpus,7,0.31,0.01,0.2788837794017795 158 | 75% Corpus,7,0.31,0.31,0.2909961139203829 159 | 75% Corpus,7,0.31,0.61,0.28852068336946435 160 | 75% Corpus,7,0.31,0.9099999999999999,0.3129742202428836 161 | 75% Corpus,7,0.31,symmetric,0.2777182230257198 162 | 75% Corpus,7,0.61,0.01,0.28327368320570007 163 | 75% Corpus,7,0.61,0.31,0.28935990578371756 164 | 75% Corpus,7,0.61,0.61,0.28852068336946435 165 | 75% Corpus,7,0.61,0.9099999999999999,0.31405801487937557 166 | 75% Corpus,7,0.61,symmetric,0.2759279034494479 167 | 75% Corpus,7,0.9099999999999999,0.01,0.28327368320570007 168 | 75% Corpus,7,0.9099999999999999,0.31,0.28722285177113666 169 | 75% Corpus,7,0.9099999999999999,0.61,0.28966178578989427 170 | 75% Corpus,7,0.9099999999999999,0.9099999999999999,0.31405801487937557 171 | 75% Corpus,7,0.9099999999999999,symmetric,0.27734639862412164 172 | 75% Corpus,7,symmetric,0.01,0.2788837794017795 173 | 75% Corpus,7,symmetric,0.31,0.2909961139203829 174 | 75% Corpus,7,symmetric,0.61,0.28852068336946435 175 | 75% Corpus,7,symmetric,0.9099999999999999,0.31628801909577303 176 | 75% Corpus,7,symmetric,symmetric,0.2756697323965734 177 | 75% Corpus,7,asymmetric,0.01,0.2853642185426731 178 | 75% Corpus,7,asymmetric,0.31,0.2907271450321393 179 | 75% Corpus,7,asymmetric,0.61,0.29361676225955274 180 | 75% Corpus,7,asymmetric,0.9099999999999999,0.2882054578232691 181 | 75% Corpus,7,asymmetric,symmetric,0.2755194552200007 182 | 75% Corpus,8,0.01,0.01,0.2808202028308223 183 | 75% Corpus,8,0.01,0.31,0.29736349070880286 184 | 75% Corpus,8,0.01,0.61,0.2981078394239831 185 | 75% Corpus,8,0.01,0.9099999999999999,0.33233988889385435 186 | 75% Corpus,8,0.01,symmetric,0.28156849418007524 187 | 75% Corpus,8,0.31,0.01,0.28097129035113944 188 | 75% Corpus,8,0.31,0.31,0.29941241997917767 189 | 75% Corpus,8,0.31,0.61,0.2960462608237895 190 | 75% Corpus,8,0.31,0.9099999999999999,0.327937391019251 191 | 75% Corpus,8,0.31,symmetric,0.28207106831879114 192 | 75% Corpus,8,0.61,0.01,0.2809772515659067 193 | 75% Corpus,8,0.61,0.31,0.2993455174990556 194 | 75% Corpus,8,0.61,0.61,0.2946710626297879 195 | 75% Corpus,8,0.61,0.9099999999999999,0.32359289177614337 196 | 75% Corpus,8,0.61,symmetric,0.28138865001186986 197 | 75% Corpus,8,0.9099999999999999,0.01,0.27976485139485124 198 | 75% Corpus,8,0.9099999999999999,0.31,0.2956217410776679 199 | 75% Corpus,8,0.9099999999999999,0.61,0.28864637585951036 200 | 75% Corpus,8,0.9099999999999999,0.9099999999999999,0.3282635584644864 201 | 75% Corpus,8,0.9099999999999999,symmetric,0.28148737285248604 202 | 75% Corpus,8,symmetric,0.01,0.2808202028308223 203 | 75% Corpus,8,symmetric,0.31,0.29736349070880286 204 | 75% Corpus,8,symmetric,0.61,0.297949677831361 205 | 75% Corpus,8,symmetric,0.9099999999999999,0.3265139021008282 206 | 75% Corpus,8,symmetric,symmetric,0.2817931736933517 207 | 75% Corpus,8,asymmetric,0.01,0.27839412750067105 208 | 75% Corpus,8,asymmetric,0.31,0.296460251572274 209 | 75% Corpus,8,asymmetric,0.61,0.297148250775704 210 | 75% Corpus,8,asymmetric,0.9099999999999999,0.32649247107917795 211 | 75% Corpus,8,asymmetric,symmetric,0.2785059288493066 212 | 75% Corpus,9,0.01,0.01,0.30218586423505117 213 | 75% Corpus,9,0.01,0.31,0.3020235109956903 214 | 75% Corpus,9,0.01,0.61,0.4185691849535152 215 | 75% Corpus,9,0.01,0.9099999999999999,0.30527967183321003 216 | 75% Corpus,9,0.01,symmetric,0.3060635646496002 217 | 75% Corpus,9,0.31,0.01,0.30068508513688286 218 | 75% Corpus,9,0.31,0.31,0.3021506007873651 219 | 75% Corpus,9,0.31,0.61,0.40687439307467294 220 | 75% Corpus,9,0.31,0.9099999999999999,0.3073421317714173 221 | 75% Corpus,9,0.31,symmetric,0.3074145374333964 222 | 75% Corpus,9,0.61,0.01,0.3008820210254886 223 | 75% Corpus,9,0.61,0.31,0.30275011169684873 224 | 75% Corpus,9,0.61,0.61,0.41015152208333183 225 | 75% Corpus,9,0.61,0.9099999999999999,0.30255055512967155 226 | 75% Corpus,9,0.61,symmetric,0.30715762371551203 227 | 75% Corpus,9,0.9099999999999999,0.01,0.3022010046079812 228 | 75% Corpus,9,0.9099999999999999,0.31,0.30477890773318156 229 | 75% Corpus,9,0.9099999999999999,0.61,0.40433106836971433 230 | 75% Corpus,9,0.9099999999999999,0.9099999999999999,0.307644042466123 231 | 75% Corpus,9,0.9099999999999999,symmetric,0.30605307577755286 232 | 75% Corpus,9,symmetric,0.01,0.3013158303146456 233 | 75% Corpus,9,symmetric,0.31,0.304290454027783 234 | 75% Corpus,9,symmetric,0.61,0.4140952699790183 235 | 75% Corpus,9,symmetric,0.9099999999999999,0.30527967183321 236 | 75% Corpus,9,symmetric,symmetric,0.3046097002166359 237 | 75% Corpus,9,asymmetric,0.01,0.30129966466596664 238 | 75% Corpus,9,asymmetric,0.31,0.30429095996678135 239 | 75% Corpus,9,asymmetric,0.61,0.41788064240742073 240 | 75% Corpus,9,asymmetric,0.9099999999999999,0.3025975330524115 241 | 75% Corpus,9,asymmetric,symmetric,0.30669601144755215 242 | 75% Corpus,10,0.01,0.01,0.29670164537919275 243 | 75% Corpus,10,0.01,0.31,0.3047813348299382 244 | 75% Corpus,10,0.01,0.61,0.31606878233356517 245 | 75% Corpus,10,0.01,0.9099999999999999,0.3377296641607972 246 | 75% Corpus,10,0.01,symmetric,0.29319673176987077 247 | 75% Corpus,10,0.31,0.01,0.29805457831216586 248 | 75% Corpus,10,0.31,0.31,0.30369633038354127 249 | 75% Corpus,10,0.31,0.61,0.30998451194916454 250 | 75% Corpus,10,0.31,0.9099999999999999,0.34268251293470897 251 | 75% Corpus,10,0.31,symmetric,0.29319673176987077 252 | 75% Corpus,10,0.61,0.01,0.29386231031811644 253 | 75% Corpus,10,0.61,0.31,0.29541931052055126 254 | 75% Corpus,10,0.61,0.61,0.309970817294693 255 | 75% Corpus,10,0.61,0.9099999999999999,0.3453018084648031 256 | 75% Corpus,10,0.61,symmetric,0.29319673176987077 257 | 75% Corpus,10,0.9099999999999999,0.01,0.2945143416112511 258 | 75% Corpus,10,0.9099999999999999,0.31,0.34045282991315623 259 | 75% Corpus,10,0.9099999999999999,0.61,0.3126412466766651 260 | 75% Corpus,10,0.9099999999999999,0.9099999999999999,0.3435699386195771 261 | 75% Corpus,10,0.9099999999999999,symmetric,0.29319673176987077 262 | 75% Corpus,10,symmetric,0.01,0.29805457831216586 263 | 75% Corpus,10,symmetric,0.31,0.30478133482993813 264 | 75% Corpus,10,symmetric,0.61,0.31606878233356517 265 | 75% Corpus,10,symmetric,0.9099999999999999,0.33772966416079714 266 | 75% Corpus,10,symmetric,symmetric,0.29319673176987077 267 | 75% Corpus,10,asymmetric,0.01,0.29815109815940033 268 | 75% Corpus,10,asymmetric,0.31,0.35146410607200645 269 | 75% Corpus,10,asymmetric,0.61,0.3196615767839669 270 | 75% Corpus,10,asymmetric,0.9099999999999999,0.34012655333540415 271 | 75% Corpus,10,asymmetric,symmetric,0.2930959026114379 272 | 100% Corpus,2,0.01,0.01,0.26049496936796 273 | 100% Corpus,2,0.01,0.31,0.2631487596403128 274 | 100% Corpus,2,0.01,0.61,0.2670430149871908 275 | 100% Corpus,2,0.01,0.9099999999999999,0.2784737874245884 276 | 100% Corpus,2,0.01,symmetric,0.2659027879879802 277 | 100% Corpus,2,0.31,0.01,0.26049496936796 278 | 100% Corpus,2,0.31,0.31,0.2631487596403128 279 | 100% Corpus,2,0.31,0.61,0.2670430149871908 280 | 100% Corpus,2,0.31,0.9099999999999999,0.2784737874245884 281 | 100% Corpus,2,0.31,symmetric,0.2659027879879802 282 | 100% Corpus,2,0.61,0.01,0.26049496936796007 283 | 100% Corpus,2,0.61,0.31,0.2631487596403128 284 | 100% Corpus,2,0.61,0.61,0.2670430149871908 285 | 100% Corpus,2,0.61,0.9099999999999999,0.27847378742458834 286 | 100% Corpus,2,0.61,symmetric,0.2659027879879803 287 | 100% Corpus,2,0.9099999999999999,0.01,0.26049496936796007 288 | 100% Corpus,2,0.9099999999999999,0.31,0.2631487596403128 289 | 100% Corpus,2,0.9099999999999999,0.61,0.2670430149871908 290 | 100% Corpus,2,0.9099999999999999,0.9099999999999999,0.27847378742458834 291 | 100% Corpus,2,0.9099999999999999,symmetric,0.2659027879879803 292 | 100% Corpus,2,symmetric,0.01,0.26049496936796007 293 | 100% Corpus,2,symmetric,0.31,0.2631487596403128 294 | 100% Corpus,2,symmetric,0.61,0.2670430149871908 295 | 100% Corpus,2,symmetric,0.9099999999999999,0.27847378742458834 296 | 100% Corpus,2,symmetric,symmetric,0.2659027879879802 297 | 100% Corpus,2,asymmetric,0.01,0.26049496936796 298 | 100% Corpus,2,asymmetric,0.31,0.2638307040567668 299 | 100% Corpus,2,asymmetric,0.61,0.2670430149871908 300 | 100% Corpus,2,asymmetric,0.9099999999999999,0.2784737874245884 301 | 100% Corpus,2,asymmetric,symmetric,0.2659027879879803 302 | 100% Corpus,3,0.01,0.01,0.27711689254474037 303 | 100% Corpus,3,0.01,0.31,0.27802374195120044 304 | 100% Corpus,3,0.01,0.61,0.27993004576503216 305 | 100% Corpus,3,0.01,0.9099999999999999,0.28461303163756196 306 | 100% Corpus,3,0.01,symmetric,0.27802374195120044 307 | 100% Corpus,3,0.31,0.01,0.2803842121014907 308 | 100% Corpus,3,0.31,0.31,0.27802374195120044 309 | 100% Corpus,3,0.31,0.61,0.27993004576503216 310 | 100% Corpus,3,0.31,0.9099999999999999,0.2836001930609014 311 | 100% Corpus,3,0.31,symmetric,0.27802374195120044 312 | 100% Corpus,3,0.61,0.01,0.2803842121014907 313 | 100% Corpus,3,0.61,0.31,0.27802374195120044 314 | 100% Corpus,3,0.61,0.61,0.28095006391110916 315 | 100% Corpus,3,0.61,0.9099999999999999,0.2836495488056456 316 | 100% Corpus,3,0.61,symmetric,0.27802374195120044 317 | 100% Corpus,3,0.9099999999999999,0.01,0.28041475692228796 318 | 100% Corpus,3,0.9099999999999999,0.31,0.27802374195120044 319 | 100% Corpus,3,0.9099999999999999,0.61,0.28095006391110916 320 | 100% Corpus,3,0.9099999999999999,0.9099999999999999,0.2836495488056456 321 | 100% Corpus,3,0.9099999999999999,symmetric,0.27802374195120044 322 | 100% Corpus,3,symmetric,0.01,0.2803842121014907 323 | 100% Corpus,3,symmetric,0.31,0.27802374195120044 324 | 100% Corpus,3,symmetric,0.61,0.27993004576503216 325 | 100% Corpus,3,symmetric,0.9099999999999999,0.2836495488056456 326 | 100% Corpus,3,symmetric,symmetric,0.27802374195120044 327 | 100% Corpus,3,asymmetric,0.01,0.2803842121014907 328 | 100% Corpus,3,asymmetric,0.31,0.27802374195120044 329 | 100% Corpus,3,asymmetric,0.61,0.28095006391110916 330 | 100% Corpus,3,asymmetric,0.9099999999999999,0.2836495488056456 331 | 100% Corpus,3,asymmetric,symmetric,0.27802374195120044 332 | 100% Corpus,4,0.01,0.01,0.2809362113240368 333 | 100% Corpus,4,0.01,0.31,0.27835632925620063 334 | 100% Corpus,4,0.01,0.61,0.27555206267257515 335 | 100% Corpus,4,0.01,0.9099999999999999,0.28446330333455255 336 | 100% Corpus,4,0.01,symmetric,0.27835632925620063 337 | 100% Corpus,4,0.31,0.01,0.2809362113240368 338 | 100% Corpus,4,0.31,0.31,0.27835632925620063 339 | 100% Corpus,4,0.31,0.61,0.27548045699445267 340 | 100% Corpus,4,0.31,0.9099999999999999,0.28446330333455255 341 | 100% Corpus,4,0.31,symmetric,0.27835632925620063 342 | 100% Corpus,4,0.61,0.01,0.2809362113240368 343 | 100% Corpus,4,0.61,0.31,0.27835632925620063 344 | 100% Corpus,4,0.61,0.61,0.27966327435739713 345 | 100% Corpus,4,0.61,0.9099999999999999,0.28446330333455255 346 | 100% Corpus,4,0.61,symmetric,0.2782671534254213 347 | 100% Corpus,4,0.9099999999999999,0.01,0.28177729599690937 348 | 100% Corpus,4,0.9099999999999999,0.31,0.27835632925620063 349 | 100% Corpus,4,0.9099999999999999,0.61,0.28263222170754976 350 | 100% Corpus,4,0.9099999999999999,0.9099999999999999,0.28446330333455255 351 | 100% Corpus,4,0.9099999999999999,symmetric,0.27749145169031925 352 | 100% Corpus,4,symmetric,0.01,0.2809362113240368 353 | 100% Corpus,4,symmetric,0.31,0.27835632925620063 354 | 100% Corpus,4,symmetric,0.61,0.27548045699445267 355 | 100% Corpus,4,symmetric,0.9099999999999999,0.28446330333455255 356 | 100% Corpus,4,symmetric,symmetric,0.27835632925620063 357 | 100% Corpus,4,asymmetric,0.01,0.2809362113240368 358 | 100% Corpus,4,asymmetric,0.31,0.27835632925620063 359 | 100% Corpus,4,asymmetric,0.61,0.27335019355355233 360 | 100% Corpus,4,asymmetric,0.9099999999999999,0.28118168667280763 361 | 100% Corpus,4,asymmetric,symmetric,0.2782671534254213 362 | 100% Corpus,5,0.01,0.01,0.3055810333138698 363 | 100% Corpus,5,0.01,0.31,0.2921971083432925 364 | 100% Corpus,5,0.01,0.61,0.29351918649837283 365 | 100% Corpus,5,0.01,0.9099999999999999,0.31027882311552357 366 | 100% Corpus,5,0.01,symmetric,0.28798663645353445 367 | 100% Corpus,5,0.31,0.01,0.3055810333138698 368 | 100% Corpus,5,0.31,0.31,0.2919593387953088 369 | 100% Corpus,5,0.31,0.61,0.29351918649837283 370 | 100% Corpus,5,0.31,0.9099999999999999,0.3013857090688862 371 | 100% Corpus,5,0.31,symmetric,0.28798663645353445 372 | 100% Corpus,5,0.61,0.01,0.30778470383924467 373 | 100% Corpus,5,0.61,0.31,0.29467018241870313 374 | 100% Corpus,5,0.61,0.61,0.29688907251265284 375 | 100% Corpus,5,0.61,0.9099999999999999,0.3013857090688862 376 | 100% Corpus,5,0.61,symmetric,0.29224715357405645 377 | 100% Corpus,5,0.9099999999999999,0.01,0.30778470383924467 378 | 100% Corpus,5,0.9099999999999999,0.31,0.2891142546834146 379 | 100% Corpus,5,0.9099999999999999,0.61,0.29749568404827875 380 | 100% Corpus,5,0.9099999999999999,0.9099999999999999,0.30064353604119265 381 | 100% Corpus,5,0.9099999999999999,symmetric,0.2903640490356588 382 | 100% Corpus,5,symmetric,0.01,0.3055810333138698 383 | 100% Corpus,5,symmetric,0.31,0.2919593387953088 384 | 100% Corpus,5,symmetric,0.61,0.29351918649837283 385 | 100% Corpus,5,symmetric,0.9099999999999999,0.3013857090688862 386 | 100% Corpus,5,symmetric,symmetric,0.28798663645353445 387 | 100% Corpus,5,asymmetric,0.01,0.3025740990082661 388 | 100% Corpus,5,asymmetric,0.31,0.2891198159919257 389 | 100% Corpus,5,asymmetric,0.61,0.2931349532251887 390 | 100% Corpus,5,asymmetric,0.9099999999999999,0.30951060360405697 391 | 100% Corpus,5,asymmetric,symmetric,0.2903640490356588 392 | 100% Corpus,6,0.01,0.01,0.2958760348579074 393 | 100% Corpus,6,0.01,0.31,0.2941800616166869 394 | 100% Corpus,6,0.01,0.61,0.2971723188349142 395 | 100% Corpus,6,0.01,0.9099999999999999,0.30879954124012965 396 | 100% Corpus,6,0.01,symmetric,0.29805452202591254 397 | 100% Corpus,6,0.31,0.01,0.2969800967267447 398 | 100% Corpus,6,0.31,0.31,0.2951136969205841 399 | 100% Corpus,6,0.31,0.61,0.2971723188349142 400 | 100% Corpus,6,0.31,0.9099999999999999,0.30879954124012965 401 | 100% Corpus,6,0.31,symmetric,0.29820145833395656 402 | 100% Corpus,6,0.61,0.01,0.2969800967267447 403 | 100% Corpus,6,0.61,0.31,0.2951136969205841 404 | 100% Corpus,6,0.61,0.61,0.2977299345012703 405 | 100% Corpus,6,0.61,0.9099999999999999,0.3049789423287517 406 | 100% Corpus,6,0.61,symmetric,0.29863606640969337 407 | 100% Corpus,6,0.9099999999999999,0.01,0.29390398336601525 408 | 100% Corpus,6,0.9099999999999999,0.31,0.2951136969205841 409 | 100% Corpus,6,0.9099999999999999,0.61,0.2957487280234154 410 | 100% Corpus,6,0.9099999999999999,0.9099999999999999,0.3049789423287517 411 | 100% Corpus,6,0.9099999999999999,symmetric,0.29863606640969337 412 | 100% Corpus,6,symmetric,0.01,0.2955217784385554 413 | 100% Corpus,6,symmetric,0.31,0.2941800616166869 414 | 100% Corpus,6,symmetric,0.61,0.2971723188349142 415 | 100% Corpus,6,symmetric,0.9099999999999999,0.30879954124012965 416 | 100% Corpus,6,symmetric,symmetric,0.29820145833395656 417 | 100% Corpus,6,asymmetric,0.01,0.2949603603199485 418 | 100% Corpus,6,asymmetric,0.31,0.2951136969205841 419 | 100% Corpus,6,asymmetric,0.61,0.2977299345012703 420 | 100% Corpus,6,asymmetric,0.9099999999999999,0.30674292283526966 421 | 100% Corpus,6,asymmetric,symmetric,0.29823105460471666 422 | 100% Corpus,7,0.01,0.01,0.30073678510163443 423 | 100% Corpus,7,0.01,0.31,0.3093075297409759 424 | 100% Corpus,7,0.01,0.61,0.2985273077717666 425 | 100% Corpus,7,0.01,0.9099999999999999,0.28108775204553077 426 | 100% Corpus,7,0.01,symmetric,0.29593451694501705 427 | 100% Corpus,7,0.31,0.01,0.3021816720953532 428 | 100% Corpus,7,0.31,0.31,0.3136135696595105 429 | 100% Corpus,7,0.31,0.61,0.30525285357617626 430 | 100% Corpus,7,0.31,0.9099999999999999,0.2810941659084761 431 | 100% Corpus,7,0.31,symmetric,0.29621498771621146 432 | 100% Corpus,7,0.61,0.01,0.3021816720953532 433 | 100% Corpus,7,0.61,0.31,0.3136135696595104 434 | 100% Corpus,7,0.61,0.61,0.30936066130234136 435 | 100% Corpus,7,0.61,0.9099999999999999,0.28629245148004184 436 | 100% Corpus,7,0.61,symmetric,0.29731679986925613 437 | 100% Corpus,7,0.9099999999999999,0.01,0.3020919465269357 438 | 100% Corpus,7,0.9099999999999999,0.31,0.3136135696595105 439 | 100% Corpus,7,0.9099999999999999,0.61,0.3151197257139406 440 | 100% Corpus,7,0.9099999999999999,0.9099999999999999,0.288468301912423 441 | 100% Corpus,7,0.9099999999999999,symmetric,0.30014119040856624 442 | 100% Corpus,7,symmetric,0.01,0.29800123606081913 443 | 100% Corpus,7,symmetric,0.31,0.3093075297409759 444 | 100% Corpus,7,symmetric,0.61,0.29852730777176656 445 | 100% Corpus,7,symmetric,0.9099999999999999,0.2833650342764223 446 | 100% Corpus,7,symmetric,symmetric,0.29621498771621146 447 | 100% Corpus,7,asymmetric,0.01,0.3014826617961082 448 | 100% Corpus,7,asymmetric,0.31,0.30946569097108306 449 | 100% Corpus,7,asymmetric,0.61,0.29780622606183804 450 | 100% Corpus,7,asymmetric,0.9099999999999999,0.27769095312678477 451 | 100% Corpus,7,asymmetric,symmetric,0.29669074530709133 452 | 100% Corpus,8,0.01,0.01,0.27689325792791325 453 | 100% Corpus,8,0.01,0.31,0.28335268992548035 454 | 100% Corpus,8,0.01,0.61,0.29447751279748635 455 | 100% Corpus,8,0.01,0.9099999999999999,0.2933443347019431 456 | 100% Corpus,8,0.01,symmetric,0.2719332438180937 457 | 100% Corpus,8,0.31,0.01,0.2778826015547943 458 | 100% Corpus,8,0.31,0.31,0.2825893964563385 459 | 100% Corpus,8,0.31,0.61,0.2939449197205991 460 | 100% Corpus,8,0.31,0.9099999999999999,0.2933443347019431 461 | 100% Corpus,8,0.31,symmetric,0.2729328842173082 462 | 100% Corpus,8,0.61,0.01,0.2778826015547943 463 | 100% Corpus,8,0.61,0.31,0.28595528080117094 464 | 100% Corpus,8,0.61,0.61,0.2927074117432516 465 | 100% Corpus,8,0.61,0.9099999999999999,0.2872200703569201 466 | 100% Corpus,8,0.61,symmetric,0.2732337709535984 467 | 100% Corpus,8,0.9099999999999999,0.01,0.27786820825055075 468 | 100% Corpus,8,0.9099999999999999,0.31,0.28418596093474835 469 | 100% Corpus,8,0.9099999999999999,0.61,0.2900190376327208 470 | 100% Corpus,8,0.9099999999999999,0.9099999999999999,0.29123665567102414 471 | 100% Corpus,8,0.9099999999999999,symmetric,0.27323377095359846 472 | 100% Corpus,8,symmetric,0.01,0.27689325792791325 473 | 100% Corpus,8,symmetric,0.31,0.28420779222803205 474 | 100% Corpus,8,symmetric,0.61,0.2952855947321743 475 | 100% Corpus,8,symmetric,0.9099999999999999,0.2933443347019431 476 | 100% Corpus,8,symmetric,symmetric,0.2725123137958163 477 | 100% Corpus,8,asymmetric,0.01,0.2761789762953015 478 | 100% Corpus,8,asymmetric,0.31,0.2799130295170522 479 | 100% Corpus,8,asymmetric,0.61,0.2948589392161668 480 | 100% Corpus,8,asymmetric,0.9099999999999999,0.2812546037633434 481 | 100% Corpus,8,asymmetric,symmetric,0.2729328842173082 482 | 100% Corpus,9,0.01,0.01,0.3055895680888938 483 | 100% Corpus,9,0.01,0.31,0.30302760647148597 484 | 100% Corpus,9,0.01,0.61,0.2996054006558133 485 | 100% Corpus,9,0.01,0.9099999999999999,0.34404649042246366 486 | 100% Corpus,9,0.01,symmetric,0.3022567927575817 487 | 100% Corpus,9,0.31,0.01,0.3050065555696478 488 | 100% Corpus,9,0.31,0.31,0.30328591827752077 489 | 100% Corpus,9,0.31,0.61,0.29917768071256 490 | 100% Corpus,9,0.31,0.9099999999999999,0.34479247631815907 491 | 100% Corpus,9,0.31,symmetric,0.30430285315228395 492 | 100% Corpus,9,0.61,0.01,0.30426709798506846 493 | 100% Corpus,9,0.61,0.31,0.3018951218284658 494 | 100% Corpus,9,0.61,0.61,0.3001071122248435 495 | 100% Corpus,9,0.61,0.9099999999999999,0.34618320085549326 496 | 100% Corpus,9,0.61,symmetric,0.30433563585169243 497 | 100% Corpus,9,0.9099999999999999,0.01,0.3055723111286964 498 | 100% Corpus,9,0.9099999999999999,0.31,0.3030863932378131 499 | 100% Corpus,9,0.9099999999999999,0.61,0.29813786201586745 500 | 100% Corpus,9,0.9099999999999999,0.9099999999999999,0.34500630064915166 501 | 100% Corpus,9,0.9099999999999999,symmetric,0.3038428140388971 502 | 100% Corpus,9,symmetric,0.01,0.3023576157049908 503 | 100% Corpus,9,symmetric,0.31,0.30302760647148597 504 | 100% Corpus,9,symmetric,0.61,0.3003121132770352 505 | 100% Corpus,9,symmetric,0.9099999999999999,0.34214587751079284 506 | 100% Corpus,9,symmetric,symmetric,0.3022567927575817 507 | 100% Corpus,9,asymmetric,0.01,0.3057340479868098 508 | 100% Corpus,9,asymmetric,0.31,0.30328591827752077 509 | 100% Corpus,9,asymmetric,0.61,0.3011057586148252 510 | 100% Corpus,9,asymmetric,0.9099999999999999,0.350861967504945 511 | 100% Corpus,9,asymmetric,symmetric,0.30251782074437106 512 | 100% Corpus,10,0.01,0.01,0.283398008758761 513 | 100% Corpus,10,0.01,0.31,0.2751258030801618 514 | 100% Corpus,10,0.01,0.61,0.2915458869869755 515 | 100% Corpus,10,0.01,0.9099999999999999,0.2948656869892196 516 | 100% Corpus,10,0.01,symmetric,0.2777952167218004 517 | 100% Corpus,10,0.31,0.01,0.28125840155500537 518 | 100% Corpus,10,0.31,0.31,0.2762321145354264 519 | 100% Corpus,10,0.31,0.61,0.29037856739931606 520 | 100% Corpus,10,0.31,0.9099999999999999,0.29658208038434386 521 | 100% Corpus,10,0.31,symmetric,0.27688479666982796 522 | 100% Corpus,10,0.61,0.01,0.2803111695414585 523 | 100% Corpus,10,0.61,0.31,0.27818213083876936 524 | 100% Corpus,10,0.61,0.61,0.2894460065949672 525 | 100% Corpus,10,0.61,0.9099999999999999,0.29802196235401307 526 | 100% Corpus,10,0.61,symmetric,0.27614054331196536 527 | 100% Corpus,10,0.9099999999999999,0.01,0.2817458696637633 528 | 100% Corpus,10,0.9099999999999999,0.31,0.2783073583069227 529 | 100% Corpus,10,0.9099999999999999,0.61,0.2889530806223174 530 | 100% Corpus,10,0.9099999999999999,0.9099999999999999,0.2950248587541427 531 | 100% Corpus,10,0.9099999999999999,symmetric,0.27614054331196536 532 | 100% Corpus,10,symmetric,0.01,0.2821805736812627 533 | 100% Corpus,10,symmetric,0.31,0.2751258030801618 534 | 100% Corpus,10,symmetric,0.61,0.2911575680096669 535 | 100% Corpus,10,symmetric,0.9099999999999999,0.2948656869892196 536 | 100% Corpus,10,symmetric,symmetric,0.2777952167218004 537 | 100% Corpus,10,asymmetric,0.01,0.2818119554111271 538 | 100% Corpus,10,asymmetric,0.31,0.2804636061791579 539 | 100% Corpus,10,asymmetric,0.61,0.29020292429978206 540 | 100% Corpus,10,asymmetric,0.9099999999999999,0.2973427325310818 541 | 100% Corpus,10,asymmetric,symmetric,0.278615868791953 542 | -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/results/ldavis_prepared_10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/topic-modeling/results/ldavis_prepared_10 -------------------------------------------------------------------------------- /natural-language-processing/topic-modeling/results/ldavis_tuned_8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kapadias/medium-articles/749c93d1e6373c7911d3076fa8bcc38997cef884/natural-language-processing/topic-modeling/results/ldavis_tuned_8 -------------------------------------------------------------------------------- /natural-language-processing/transformers-series/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "transformers-models" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Shashank Kapadia "] 6 | readme = "README.md" 7 | 8 | [tool.poetry.dependencies] 9 | python = ">=3.9,<3.10" 10 | jupyterlab = "^4.0.2" 11 | tensorflow = [ 12 | { version = "2.10.0", platform = "linux" }, 13 | ] 14 | tensorflow-macos = [ 15 | { version = "2.10.0", platform = "darwin" }, 16 | ] 17 | pandas = "^2.0.3" 18 | seaborn = "^0.12.2" 19 | transformers = "4.30.0" 20 | torch = "^2.0.1" 21 | scikit-learn = "^1.3.0" 22 | datasets = "^2.13.1" 23 | accelerate = "^0.20.3" 24 | 25 | 26 | [build-system] 27 | requires = ["poetry-core"] 28 | build-backend = "poetry.core.masonry.api" 29 | -------------------------------------------------------------------------------- /recommender/results/profiler_interactions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Profile report 8 | 9 | 10 | 11 | 12 | 14 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 234 | 235 |
236 |
237 |

Overview

238 |
239 |
240 |
241 |

Dataset info

242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 |
Number of variables2
Number of observations2734350
Total Missing (%)0.0%
Total size in memory41.7 MiB
Average record size in memory16.0 B
266 |
267 |
268 |

Variables types

269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 |
Numeric1
Categorical1
Date0
Text (Unique)0
Rejected0
293 |
294 |
295 |

Warnings

296 |
  • rating has 1505291 / 55.1% zeros
  • Dataset has 2734343 duplicate rows Warning
297 |
298 |
299 |
300 |

Variables

301 |
302 |
303 |
304 |

is_read
305 | Categorical 306 |

307 |
308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 |
Distinct count2
Unique (%)0.0%
Missing (%)0.0%
Missing (n)0
326 |
327 |
328 | 329 | 330 | 331 | 338 | 339 | 340 | 347 | 348 |
false 332 |
334 | 1420740 335 |
336 | 337 |
true 341 |
343 | 1313610 344 |
345 | 346 |
349 |
350 | 356 |
357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 374 | 375 | 376 | 377 | 378 | 381 | 382 |
ValueCountFrequency (%) 
false142074052.0% 372 |
 
373 |
true131361048.0% 379 |
 
380 |
383 |
384 |
385 |
386 |

rating
387 | Numeric 388 |

389 |
390 |
391 |
392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
Distinct count6
Unique (%)0.0%
Missing (%)0.0%
Missing (n)0
Infinite (%)0.0%
Infinite (n)0
418 | 419 |
420 |
421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 |
Mean1.8248
Minimum0
Maximum5
Zeros (%)55.1%
440 |
441 |
442 |
443 |
444 | 445 | 446 |
447 | 453 |
454 | 466 | 467 |
468 |
469 |
470 |

Quantile statistics

471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 |
Minimum0
5-th percentile0
Q10
Median0
Q34
95-th percentile5
Maximum5
Range5
Interquartile range4
509 |
510 |
511 |

Descriptive statistics

512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 |
Standard deviation2.1232
Coef of variation1.1635
Kurtosis-1.6116
Mean1.8248
MAD2.0215
Skewness0.4371
Sum4989606
Variance4.5081
Memory size20.9 MiB
550 |
551 |
552 |
553 | 554 |
555 |
556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 573 | 574 | 575 | 576 | 577 | 580 | 581 | 582 | 583 | 584 | 587 | 588 | 589 | 590 | 591 | 594 | 595 | 596 | 597 | 598 | 601 | 602 | 603 | 604 | 605 | 608 | 609 |
ValueCountFrequency (%) 
0150529155.1% 571 |
 
572 |
550097118.3% 578 |
 
579 |
440556514.8% 585 |
 
586 |
32379428.7% 592 |
 
593 |
2640842.3% 599 |
 
600 |
1204970.7% 606 |
 
607 |
610 |
611 |
612 |

Minimum 5 values

613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 630 | 631 | 632 | 633 | 634 | 637 | 638 | 639 | 640 | 641 | 644 | 645 | 646 | 647 | 648 | 651 | 652 | 653 | 654 | 655 | 658 | 659 |
ValueCountFrequency (%) 
0150529155.1% 628 |
 
629 |
1204970.7% 635 |
 
636 |
2640842.3% 642 |
 
643 |
32379428.7% 649 |
 
650 |
440556514.8% 656 |
 
657 |
660 |

Maximum 5 values

661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 678 | 679 | 680 | 681 | 682 | 685 | 686 | 687 | 688 | 689 | 692 | 693 | 694 | 695 | 696 | 699 | 700 | 701 | 702 | 703 | 706 | 707 |
ValueCountFrequency (%) 
1204970.7% 676 |
 
677 |
2640842.3% 683 |
 
684 |
32379428.7% 690 |
 
691 |
440556514.8% 697 |
 
698 |
550097118.3% 704 |
 
705 |
708 |
709 |
710 |
711 |
712 |
713 |

Sample

714 |
715 |
716 |
717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 |
is_readrating
0true4
1true4
2true5
3false0
4true3
753 |
754 |
755 |
756 | 757 | --------------------------------------------------------------------------------