euagendas / m3inference

A deep learning system for demographic inference (gender, age, and individual/person) that was trained on massive Twitter dataset using profile images, screen names, names, and biographies
http://www.euagendas.org
GNU Affero General Public License v3.0
145 stars 57 forks source link

Infer_ad and infer_username can't work well #32

Closed agungmarwan23 closed 2 years ago

agungmarwan23 commented 2 years ago

I have probelm while running program, my code is

#The API first needs to validate your Twitter App's credentials m3twitter.twitter_init_from_file('/content/drive/My Drive/Ibu Avi/Last/User/auth-sample.txt')

The output is : True

And #sample run pprint.pprint(m3twitter.infer_id("3138075595"))

The output is :

_04/27/2022 09:40:21 - INFO - m3inference.m3twitter - Results not in cache. Fetching data from Twitter for id 3138075595. 04/27/2022 09:40:21 - INFO - m3inference.m3twitter - GET /users/show.json?id=3138075595 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Could not retreive screen_name 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Could not retreive id_str 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Could not retreive description 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Could not retreive name 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Could not retreive profile_image_url 04/27/2022 09:40:21 - WARNING - m3inference.m3twitter - Unable to extract image from Twitter. Using default image. 04/27/2022 09:40:21 - INFO - m3inference.dataset - 1 data entries loaded. Predicting...: 100%|██████████| 1/1 [00:00<00:00, 1.39it/s]{'input': {'description': '', 'id': 'dummy', 'img_path': '/usr/local/lib/python3.7/dist-packages/m3inference/data/tw_default_profile.png', 'lang': 'un', 'name': '', 'screenname': ''}, 'output': {'age': {'19-29': 0.2393, '30-39': 0.0793, '<=18': 0.1746, '>=40': 0.5067}, 'gender': {'female': 0.2809, 'male': 0.7191}, 'org': {'is-org': 0.0873, 'non-org': 0.9127}}}

Its always like that even after change other active user id and username, what should i do?

computermacgyver commented 2 years ago

Please check your Twitter credentials. These should be credentials for the v1.1 API, not the v2 API. I am able to reproduce this behaviour if the Twitter credentials are invalid. If they are valid, the example succeeds.

python 
Python 3.8.8 (default, Apr 13 2021, 19:58:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import m3inference
>>> m3tw=m3inference.m3twitter.M3Twitter()
04/27/2022 11:05:34 - INFO - m3inference.m3inference -   Version 1.1.5
04/27/2022 11:05:34 - INFO - m3inference.m3inference -   Running on cpu.
04/27/2022 11:05:34 - INFO - m3inference.m3inference -   Will use full M3 model.
04/27/2022 11:05:34 - INFO - m3inference.m3inference -   Model full_model exists at ...
04/27/2022 11:05:34 - INFO - m3inference.utils -   Checking MD5 for model full_model at ...
04/27/2022 11:05:34 - INFO - m3inference.utils -   MD5s match.
04/27/2022 11:05:35 - INFO - m3inference.m3inference -   Loaded pretrained weight at ...
>>> m3tw.twitter_init_from_file("auth.txt")
True
>>> import pprint
>>> pprint.pprint(m3tw.infer_id("3138075595",skip_cache=True))
04/27/2022 11:06:23 - INFO - m3inference.m3twitter -   skip_cache is True. Fetching data from Twitter for id 3138075595.
04/27/2022 11:06:23 - INFO - m3inference.m3twitter -   GET /users/show.json?id=3138075595
04/27/2022 11:06:24 - INFO - m3inference.dataset -   1 data entries loaded.
Predicting...: 100%|████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  3.25it/s]
{'input': {'description': 'Media untuk mencerdaskan bangsa dan negara',
           'id': '3138075595',
           'img_path': '/.../m3/cache/3138075595_224x224.jpg',
           'lang': 'un',
           'name': 'Arrahmah News',
           'screen_name': 'NewsArrahmah'},
 'output': {'age': {'19-29': 0.1863,
                    '30-39': 0.0309,
                    '<=18': 0.0277,
                    '>=40': 0.7551},
            'gender': {'female': 0.2143, 'male': 0.7857},
            'org': {'is-org': 0.8668, 'non-org': 0.1332}}}