Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix incorrect __eq__ method of AttackedText in textattack/shared/attacked_text.py #509

Merged
merged 17 commits into from
Sep 22, 2021

Conversation

wenh06
Copy link
Contributor

@wenh06 wenh06 commented Aug 3, 2021

What does this PR do?

Summary

fix incorrect __eq__ method of AttackedText in textattack/shared/attacked_text.py

Another thing is that I added DownloadConfig in textattack/datasets/huggingface_dataset.py to try to use a proxy for downloading things from huggingface. This is irrelevant to this pull request.

Additions

  • in the __eq__ method of AttackedText, an additional check of equal number of dict items of attack_attrs is added. If this correction was not done, the __eq__ is incorrect, as illustrated in the following example
from textattack.shared.attacked_text import AttackedText
at1 = AttackedText("hehe", attack_attrs={"hehe":1})
at2 = AttackedText("hehe", attack_attrs={"hehe":1, "haha":2})

print(at1 == at2)
print(at2 == at1)

whose outcome would be

True
False

Changes

  • NA

Deletions

  • NA

Checklist

  • [√] The title of your pull request should be a summary of its contribution.
  • [√] Please write detailed description of what parts have been newly added and what parts have been modified. Please also explain why certain changes were made.
  • [√] If your pull request addresses an issue, please mention the issue number in the pull request description to make sure they are linked (and people consulting the issue know you are working on it)
  • [√] To indicate a work in progress please mark it as a draft on Github.
  • [√] Make sure existing tests pass.
  • [√] Add relevant tests. No quality testing = no merge.
  • [√] All public methods must have informative docstrings that work nicely with sphinx. For new modules/files, please add/modify the appropriate .rst file in TextAttack/docs/apidoc.'

@qiyanjun
Copy link
Member

qiyanjun commented Aug 6, 2021

@cogeid please review

@qiyanjun qiyanjun requested a review from jinyongyoo August 21, 2021 18:24
@qiyanjun
Copy link
Member

@wenh06 thanks for the PR.

What is the purpose of "added DownloadConfig in textattack/datasets/huggingface_dataset.py to try to use a proxy for downloading things from huggingface."?

What purpose is this addition for?

@wenh06
Copy link
Contributor Author

wenh06 commented Aug 22, 2021

@wenh06 thanks for the PR.

What is the purpose of "added DownloadConfig in textattack/datasets/huggingface_dataset.py to try to use a proxy for downloading things from huggingface."?

What purpose is this addition for?

My direct connection to github (huggingface datasets download things from raw.githubusercontent) is usually poor, so I added this. If it is useless to most users, I think it can be removed. Thank you.

@sanchit97
Copy link
Contributor

@wenh06 Thank you for the PR!

  1. The __eq__ method's check was an oversight, we should check both directions.
  2. The index bug in first_word_diff was also an oversight, mostly because the method is never referenced, its an added utility.
  3. DownloadConfig can be removed in the huggingface_dataset.py file. Can you remove them from the PR?

@qiyanjun I think the changes in attacked_text.py are ready to merge.

download config was added in previous 2 commits, which is useless for most of the people, hence is removed.
@wenh06
Copy link
Contributor Author

wenh06 commented Sep 3, 2021

3. DownloadConfig is removed now.

@sanchit97
Copy link
Contributor

@wenh06 Thanks a lot! Ready to merge after checks.

@qiyanjun
Copy link
Member

qiyanjun commented Sep 3, 2021

@wenh06 can you fix the formatting errors / then the pytest errors? thanks

@wenh06
Copy link
Contributor Author

wenh06 commented Sep 4, 2021

@wenh06 can you fix the formatting errors / then the pytest errors? thanks

These errors are caused by recent updates of setuptools_scm, see this issue and another issue. The latest version might have fixed this. Try another merge and it might work now.

@wenh06
Copy link
Contributor Author

wenh06 commented Sep 4, 2021

@wenh06 can you fix the formatting errors / then the pytest errors? thanks

Almost all errors happened during installing dependencies as follows

Collecting black==20.8b1
  Downloading black-20.8b1.tar.gz (1.1 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /opt/hostedtoolcache/Python/3.8.11/x64/bin/python /opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /tmp/tmprk_1nyhe
         cwd: /tmp/pip-install-uksyxpdr/black_9e371aff060b4f01a802c90b27fa15f8
    Complete output (30 lines):
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
        main()
      File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 151, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 166, in prepare_metadata_for_build_wheel
        self.run_setup()
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 150, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 48, in <module>
        setup(
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 455, in __init__
        _Distribution.__init__(self, {
      File "/opt/hostedtoolcache/Python/3.8.11/x64/lib/python3.8/distutils/dist.py", line 292, in __init__
        self.finalize_options()
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 807, in finalize_options
        ep(self)
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools_scm/integration.py", line 90, in infer_version
        config = Configuration.from_file(dist_name=dist_name)
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools_scm/config.py", line 181, in from_file
        defn = _load_toml(data)
      File "/tmp/pip-build-env-6h_d7wkj/overlay/lib/python3.8/site-packages/setuptools_scm/config.py", line 53, in _lazy_tomli_load
        from tomli import loads
    ModuleNotFoundError: No module named 'tomli'

@sanchit97
Copy link
Contributor

Looks like the workflow is still loading in the broken black package.
One simple fix would be to create a new PR and discard this one because Actions would be forced to re-run from scratch. (The issue has been fixed from their end)

@qiyanjun
Copy link
Member

qiyanjun commented Sep 9, 2021 via email

@wenh06
Copy link
Contributor Author

wenh06 commented Sep 11, 2021

Looks like the workflow is still loading in the broken black package.
One simple fix would be to create a new PR and discard this one because Actions would be forced to re-run from scratch. (The issue has been fixed from their end)

May I can add several commits, since I found some other typos.

there's no member fout in the CSVLogger, and there's no fout assigned to instances of CSVLogger elsewhere in Textattack
@wenh06
Copy link
Contributor Author

wenh06 commented Sep 22, 2021

I fixed #526 here @jxmorris12

@jxmorris12
Copy link
Collaborator

Thanks @wenh06 - LGTM! running the tests now

@qiyanjun
Copy link
Member

@Hanyu-Liu-123 mind helping me check this for one more time?

@qiyanjun qiyanjun requested review from jxmorris12 and Hanyu-Liu-123 and removed request for jinyongyoo September 22, 2021 19:50
@Hanyu-Liu-123
Copy link
Collaborator

@Hanyu-Liu-123 mind helping me check this for one more time?

no problem!

@jxmorris12 jxmorris12 merged commit cdfcba4 into QData:master Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants