News App That Detects Bias. I built a new app for your phone that… | by Adrian Krywiak | Nov, 2023


I built a new app for your phone that helps you to detect biases in news articles. Here’s how I did it.

Starting with the idea, I looked through Apple News and Google News and asked myself: “What political bias was this article written with?” I realized that there are many people out there who struggle to find reliable news sources that are free from political bias. They want to stay informed about what’s happening in the world, but they don’t want to be misled by news articles written with an agenda. That’s when I thought of creating an app that tells users what political bias an article has.

I had two options since I wanted to put this on my Apple device. Option one was Flutter, and option two was to learn Swift. I focused primarily on Apple devices since most people I knew had Apple devices. I could concentrate on Andiord-based devices later. I took a crash course on YouTube to learn all the basics of Swift. (I recommend CodeWithCrhis; he simplifies the learning process.) After I had all the necessary skills, I said, “Let’s start building.”

The first thing I tackled in this massive project was the AI model specifically. I decided to use TensorFlow for fine-tuning the ‘Bert-base-uncased’ because Bert already understands the meaning of words, which is critical in identifying bias. So, I fed in 2 key data points from an open-source repository on GitHub: a news article’s content and the tendency to be “left”, “center”, and “right.” I had to preprocess the data to remove stop words that would confuse the model. I set the bias values so that the left would be 0, the centre would be 1, and the right would be 2. Next, I spent hours and even days training and fine-tuning the model. I eventually hit a decent prediction accuracy rate of around 80 percent. Now, it’s not that high, but considering the speed was pretty fast, it was good enough. I do plan on refining the model later on.

With the AI model out of the way, I had to start gathering news articles I could send to the user’s devices. I started playing around in Python and eventually had an idea. I was going to scrape websites of news sources and gather all the article data, which would be fed into the AI model and then stored in a database. To achieve this, I had to use the inspect element on Chrome to figure out the web structure of CNN and other news sources. After hours and hours of figuring out how each website worked and all the ID and element names, I was ready to start coding. I used BeautifulSoup to do the web scraping for me. I opened up CNN and started gathering the data, such as the Title, author, date, link, text body, category, etc., of each article. I scraped all available website links; for example, CNN had around 13 classes, which all had to be sorted respectively. After this, I had to process the data through the AI model I created, but I overlooked one major issue. Bert could only process 512 tokens, so I had to find a workaround. The solution that I came up with was quite simple. Take the average of each prediction, which would be the final prediction of each article. After that, it would be stored in the database of articles, running 24/7, gathering articles.

With the article scrapper running, I was ready to make the API the user would interact with to make the app work on their device. The endpoints created would have a list of user info, including interactions with articles, etc. I stored all emails and passwords offsite on Firebase for security; the only identifier was a unique user ID. Other endpoints include the updated categories, the detect bias endpoint, news source info, and, most importantly, the articles posted today. This all got put together through a simple Flask application for testing.

Finally, the user experience took a lot of work. I had to start downloading X-Code on my MacBook and was off looking through many online tutorials. The app functions on the APIs for all the data; that’s why I said earlier that the API is the backbone of this project. I started by creating the feed user view and populating it with articles from the ‘today_articles’ endpoint. Once I tackled that part, the real challenge awaited me: the authentication. Being a novice to Swift as a whole, I had to do some digging on how to authenticate my users, and I found Firebase; it has excellent integration with Swift, so I decided to use that. It took me around two days to fully understand how to get Swift and Firebase to connect and all the functions, such as Authentication Manager, etc. After I overcame all the hurdles, I eventually had a fully functioning app that I could start testing, and boy, did it feel good to have something that worked.

The end result was a pretty decent MVP. I had a few people try it out and got positive feedback and some great suggestions to make it better. What was really cool was that everyone who tried it thought it was something they would use. Not too shabby for a first pass!

The project I worked on was an excellent opportunity to expand my skill set. While I was already familiar with Python, AI/TensorFlow, and APIs, I had to learn Swift from scratch and figure out how to integrate it with the other technologies. It was a challenging but rewarding experience, as I gained a deeper understanding of how different technologies can work together to create a functional and cohesive project. Overall, I’m grateful for the opportunity to learn and grow, and I look forward to applying my new skills to future projects. And that’s how I built a News app on your iPhone; I hope you found this article informative or learned something new!



Source link

Be the first to comment

Leave a Reply

Your email address will not be published.


*